Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[master] Console, Portal : maintenance mode #10585

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 51 additions & 3 deletions gravitee-apim-console-webui/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,41 @@
}

#gravitee-error {
color: red;
font-size: 20px;
display: none;
}

.index__gravitee-error-banner {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
z-index: 999999;

border: 3px solid #fe733f;
color: #2c0c01;
display: flex;
flex-direction: row;
align-items: center;
padding: 12px 16px;
border-radius: 8px;
background-color: #fff;
}

.index__gravitee-error-banner__icon {
display: flex;
align-self: flex-start;
margin-right: 16px;
color: #fe733f;
height: 24px;
width: 24px;
}

.index__gravitee-error-banner__message {
display: flex;
flex: 1 1 auto;
flex-direction: column;
align-items: flex-start;
line-height: normal;
}
</style>
<script language="JavaScript">
Expand Down Expand Up @@ -126,7 +154,27 @@
</p>

<app-root>
<div id="gravitee-error"></div>
<div id="gravitee-error">
<div class="index__gravitee-error-banner">
<div class="index__gravitee-error-banner__icon">
<svg fill="none" viewBox="0 0 24 24" fit="" height="100%" width="100%" preserveAspectRatio="xMidYMid meet" focusable="false">
<g>
<path
fill="currentColor"
d="M12 7a1 1 0 0 1 1 1v4a1 1 0 1 1-2 0V8a1 1 0 0 1 1-1Zm.679 8.256a1 1 0 0 1 .074 1.412l-.01.011a1 1 0 0 1-1.486-1.338l.01-.011a1 1 0 0 1 1.412-.074Z"
></path>
<path
fill="currentColor"
d="M12 3a9 9 0 0 0-9 9c0 1.641.438 3.177 1.203 4.5a1 1 0 0 1 .118.683L3.75 20.25l3.067-.57a1 1 0 0 1 .684.117A8.955 8.955 0 0 0 12 21a9 9 0 1 0 0-18ZM1 12C1 5.925 5.925 1 12 1s11 4.925 11 11-4.925 11-11 11a10.95 10.95 0 0 1-5.17-1.289l-4.147.772a1 1 0 0 1-1.166-1.166l.772-4.146A10.956 10.956 0 0 1 1 12Z"
></path>
</g>
</svg>
</div>

<div id="gravitee-error-banner-message" class="index__gravitee-error-banner__message"></div>
</div>
</div>

<div id="loader" ng-show="displayLoader" class="gravitee-splash-screen">
<div class="gravitee-loader">
<svg fill="none" viewBox="0 0 24 24" fit="" height="100%" width="100%" preserveAspectRatio="xMidYMid meet" focusable="false">
Expand Down
25 changes: 21 additions & 4 deletions gravitee-apim-console-webui/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function fetchData(): Promise<{ constants: Constants; build: any }> {
enforcedOrganizationId ? `${baseURL}/v2/ui/bootstrap?organizationId=${enforcedOrganizationId}` : `${baseURL}/v2/ui/bootstrap`,
requestConfig,
)
.then((r) => r.json())
.then((r) => getSuccessJsonDataOrThrowError(r))
.then((bootstrapResponse: { baseURL: string; organizationId: string }) => ({
bootstrapResponse,
build: buildResponse,
Expand All @@ -78,9 +78,9 @@ function fetchData(): Promise<{ constants: Constants; build: any }> {
constants.production = production ?? true;

return Promise.all([
fetch(`${constants.org.baseURL}/console`, requestConfig).then((r) => r.json()),
fetch(`${constants.org.baseURL}/console`, requestConfig).then((r) => getSuccessJsonDataOrThrowError(r)),
fetch(`${constants.org.v2BaseURL}/ui/customization`, requestConfig).then((r) => (r.status === 200 ? r.json() : null)),
fetch(`${constants.org.baseURL}/social-identities`, requestConfig).then((r) => r.json()),
fetch(`${constants.org.baseURL}/social-identities`, requestConfig).then((r) => getSuccessJsonDataOrThrowError(r)),
]).then(([consoleResponse, uiCustomizationResponse, identityProvidersResponse]) => {
constants.org.settings = consoleResponse;
constants.org.identityProviders = identityProvidersResponse;
Expand All @@ -97,7 +97,10 @@ function fetchData(): Promise<{ constants: Constants; build: any }> {
});
})
.catch((error) => {
document.getElementById('gravitee-error').innerText = 'Management API unreachable or error occurs, please check logs';
document.getElementById('gravitee-error').style.display = 'block';
document.getElementById('gravitee-error-banner-message').innerText =
error.message ?? 'Management API unreachable or error occurs, please check logs';
document.getElementById('loader').style.display = 'none';
throw error;
});
}
Expand Down Expand Up @@ -200,3 +203,17 @@ function bootstrapApplication(constants: Constants) {
console.error(err);
});
}

function getSuccessJsonDataOrThrowError(response: Response): Promise<any> {
if (!response.ok) {
return response
.json()
.catch(() => {
throw new Error('Management API unreachable or error occurs, please check logs');
})
.then((json) => {
throw new Error(json.error?.message ?? json.message ?? 'Management API unreachable or error occurs');
});
}
return response.json();
}
34 changes: 19 additions & 15 deletions gravitee-apim-portal-webui-next/src/app/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ import { provideHttpClient, withInterceptors } from '@angular/common/http';
import { APP_INITIALIZER, ApplicationConfig } from '@angular/core';
import { MAT_RIPPLE_GLOBAL_OPTIONS } from '@angular/material/core';
import { provideAnimations } from '@angular/platform-browser/animations';
import { provideRouter, withComponentInputBinding, withRouterConfig } from '@angular/router';
import { combineLatest, Observable, switchMap } from 'rxjs';
import { provideRouter, Router, withComponentInputBinding, withRouterConfig } from '@angular/router';
import { catchError, combineLatest, Observable, switchMap } from 'rxjs';
import { of } from 'rxjs/internal/observable/of';

import { routes } from './app.routes';
import { csrfInterceptor } from '../interceptors/csrf.interceptor';
Expand All @@ -33,20 +34,23 @@ function initApp(
themeService: ThemeService,
currentUserService: CurrentUserService,
portalMenuLinksService: PortalMenuLinksService,
router: Router,
): () => Observable<unknown> {
return () =>
configService
.initBaseURL()
.pipe(
switchMap(_ =>
combineLatest([
themeService.loadTheme(),
currentUserService.loadUser(),
configService.loadConfiguration(),
portalMenuLinksService.loadCustomLinks(),
]),
),
);
configService.initBaseURL().pipe(
switchMap(_ =>
combineLatest([
themeService.loadTheme(),
currentUserService.loadUser(),
configService.loadConfiguration(),
portalMenuLinksService.loadCustomLinks(),
]),
),
catchError(error => {
router.navigate(['/503'], { state: error });
return of({});
}),
);
}

export const appConfig: ApplicationConfig = {
Expand All @@ -57,7 +61,7 @@ export const appConfig: ApplicationConfig = {
{
provide: APP_INITIALIZER,
useFactory: initApp,
deps: [ConfigService, ThemeService, CurrentUserService, PortalMenuLinksService],
deps: [ConfigService, ThemeService, CurrentUserService, PortalMenuLinksService, Router],
multi: true,
},
// Ripple does not work with hsl mixing
Expand Down
2 changes: 2 additions & 0 deletions gravitee-apim-portal-webui-next/src/app/app.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { GuidesComponent } from './guides/guides.component';
import { LogInComponent } from './log-in/log-in.component';
import { LogOutComponent } from './log-out/log-out.component';
import { NotFoundComponent } from './not-found/not-found.component';
import { ServiceUnavailableComponent } from './service-unavailable/service-unavailable.component';
import { anonymousGuard } from '../guards/anonymous.guard';
import { authGuard } from '../guards/auth.guard';
import { redirectGuard } from '../guards/redirect.guard';
Expand Down Expand Up @@ -159,6 +160,7 @@ export const routes: Routes = [
{ path: 'log-in', component: LogInComponent, canActivate: [redirectGuard, anonymousGuard] },
{ path: 'log-out', component: LogOutComponent, canActivate: [redirectGuard, authGuard] },
{ path: '404', component: NotFoundComponent },
{ path: '503', component: ServiceUnavailableComponent },
{
path: '**',
component: NotFoundComponent,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!--

Copyright (C) 2024 The Gravitee team (http://gravitee.io)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

-->
<mat-card appearance="outlined" class="service-unavailable__card">
<mat-card-header>
<mat-card-title i18n="@@notFoundTitle"> Service Unavailable </mat-card-title>
</mat-card-header>
<mat-card-content>
{{ message }}
</mat-card-content>
</mat-card>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright (C) 2024 The Gravitee team (http://gravitee.io)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
.not-found__card {
display: flex;
flex-flow: column;
gap: 12px;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (C) 2024 The Gravitee team (http://gravitee.io)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Component, inject, OnInit } from '@angular/core';
import { MatCard, MatCardContent, MatCardHeader, MatCardTitle } from '@angular/material/card';
import { ActivatedRoute, Router, RouterModule } from '@angular/router';
import { get } from 'lodash';

@Component({
selector: 'app-service-unavailable',
standalone: true,
imports: [MatCard, MatCardTitle, MatCardContent, RouterModule, MatCardHeader],
templateUrl: './service-unavailable.component.html',
styleUrl: './service-unavailable.component.scss',
})
export class ServiceUnavailableComponent implements OnInit {
public activatedRoute = inject(ActivatedRoute);
public router = inject(Router);

public message = 'Portal API unreachable or error occurs, please check logs';

ngOnInit() {
const state = this.router.lastSuccessfulNavigation?.extras.state;
const error = get(state, 'errors[0]');
if (error?.code === 'errors.maintenance.mode') {
this.message = error.message;
}
}
}
1 change: 1 addition & 0 deletions gravitee-apim-portal-webui-next/src/proxy.conf.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export default [
});
proxyRes.on('end', function() {
body = body.toString();
res.writeHead(proxyRes.statusCode);
res.end(body.replace(`${target}/`, ""));
});
})
Expand Down
2 changes: 2 additions & 0 deletions gravitee-apim-portal-webui/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import { authGuard } from './services/auth-guard.service';
import { permissionsResolver } from './resolvers/permissions-resolver.service';
import { featureGuard } from './services/feature-guard.service';
import { permissionGuard } from './services/permission-guard.service';
import { MaintenanceModeComponent } from './pages/maintenance-mode/maintenance-mode.component';

export const routes: Routes = [
{ path: '', component: HomepageComponent, data: { title: 'route.homepage', menu: false, animation: { type: 'fade' } } },
Expand Down Expand Up @@ -336,6 +337,7 @@ export const routes: Routes = [
},
},
{ path: 'cookies', component: CookiesComponent, data: { title: 'route.cookies' } },
{ path: 'maintenance-mode', component: MaintenanceModeComponent, data: { title: 'Maintenance' } },
{ path: '**', component: NotFoundComponent, data: { title: 'route.notFound' } },
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export class ApiRequestInterceptor implements HttpInterceptor {
) {}

intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
const URLS_TO_IGNORE = [`/portal/ui/bootstrap`];
const headers = {
'X-Requested-With': 'XMLHttpRequest',
};
Expand All @@ -84,6 +85,10 @@ export class ApiRequestInterceptor implements HttpInterceptor {
withCredentials: true,
});

if (URLS_TO_IGNORE.some(url => request.url.endsWith(url))) {
return next.handle(request);
}

return next.handle(request).pipe(
tap(
(event: HttpEvent<any>) => {
Expand Down Expand Up @@ -125,6 +130,9 @@ export class ApiRequestInterceptor implements HttpInterceptor {
if (error.status === '503') {
// configuration has been updated, we have to reload the configuration
this.configService.load();
if (error.code === 'errors.maintenance.mode') {
interceptorFuture.push(() => this.router.navigate(['/maintenance-mode']));
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Copyright (C) 2015 The Gravitee team (http://gravitee.io)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!--

Copyright (C) 2015 The Gravitee team (http://gravitee.io)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

-->
<h2>Maintenance mode</h2>
Loading