Skip to content

Commit e1a3267

Browse files
authored
Add maintenance page (#2710)
* Add caller to health check endpoint * Disable frontend on health check fail
1 parent a35b239 commit e1a3267

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/commons/application/ApplicationWrapper.tsx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
import { useMemo } from 'react';
1+
import { Classes, NonIdealState } from '@blueprintjs/core';
2+
import { IconNames } from '@blueprintjs/icons';
3+
import classNames from 'classnames';
4+
import { useEffect, useMemo, useState } from 'react';
25
import { useDispatch } from 'react-redux';
36
import { RouterProvider } from 'react-router';
47
import { createBrowserRouter } from 'react-router-dom';
58

69
import { getFullAcademyRouterConfig, playgroundOnlyRouterConfig } from '../../routes/routerConfig';
10+
import { getHealth } from '../sagas/RequestsSaga';
711
import Constants from '../utils/Constants';
812
import { useSession } from '../utils/Hooks';
913
import { updateReactRouter } from './actions/CommonsActions';
@@ -19,6 +23,11 @@ import { updateReactRouter } from './actions/CommonsActions';
1923
const ApplicationWrapper: React.FC = () => {
2024
const dispatch = useDispatch();
2125
const { isLoggedIn, role, name, courseId } = useSession();
26+
const [isApiHealthy, setIsApiHealthy] = useState(true);
27+
28+
useEffect(() => {
29+
getHealth().then(res => setIsApiHealthy(!!res));
30+
}, []);
2231

2332
const router = useMemo(() => {
2433
const routerConfig = Constants.playgroundOnly
@@ -36,6 +45,18 @@ const ApplicationWrapper: React.FC = () => {
3645
return r;
3746
}, [isLoggedIn, role, name, courseId, dispatch]);
3847

48+
if (!isApiHealthy) {
49+
return (
50+
<div className={classNames('NoPage', Classes.DARK)}>
51+
<NonIdealState
52+
icon={IconNames.WRENCH}
53+
title="Under maintenance"
54+
description="The Source Academy is currently undergoing maintenance. Please try again later."
55+
/>
56+
</div>
57+
);
58+
}
59+
3960
return <RouterProvider router={router} />;
4061
};
4162

src/commons/sagas/RequestsSaga.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,19 @@ import {
4848
} from '../assessment/AssessmentTypes';
4949
import { Notification } from '../notificationBadge/NotificationBadgeTypes';
5050
import { castLibrary } from '../utils/CastBackend';
51+
import Constants from '../utils/Constants';
5152
import { showWarningMessage } from '../utils/notifications/NotificationsHelper';
5253
import { request } from '../utils/RequestHelper';
5354

55+
/**
56+
* GET /
57+
* (health check)
58+
*/
59+
export const getHealth = async (): Promise<Response | null> => {
60+
const resp = await request('', 'GET', {}, Constants.backendUrl);
61+
return resp;
62+
};
63+
5464
/**
5565
* POST /auth/login
5666
*/

0 commit comments

Comments
 (0)