Skip to content
This repository was archived by the owner on Feb 10, 2025. It is now read-only.

Commit fc92e60

Browse files
committed
add: devops / kubernetes health check pages
1 parent 67b0e86 commit fc92e60

3 files changed

Lines changed: 54 additions & 10 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import Head from "next/head";
2+
import Layout from "./layout";
3+
4+
/* Separate healthcheck page that does no GraphQL queries to avoid csrf token issues */
5+
export default function Index() {
6+
return (
7+
<>
8+
<Head>
9+
<meta name="robots" content="noindex,nofollow" />
10+
</Head>
11+
<Layout>
12+
<div>Healthcheck</div>
13+
</Layout>
14+
</>
15+
);
16+
}

apps/ui/middleware.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,31 @@ function redirectProtectedRoute(req: NextRequest) {
3131
return undefined;
3232
}
3333

34-
/// are we missing a csrf token in cookies and should redirect to get one
34+
/// are we missing a csrf token in cookies
35+
/// if so get the backend url to redirect to and add the current url as a redirect_to parameter
3536
function redirectCsrfToken(req: NextRequest): URL | undefined {
37+
const { cookies } = req;
38+
const hasCsrfToken = cookies.has("csrftoken");
39+
if (hasCsrfToken) {
40+
return undefined;
41+
}
42+
3643
// need to ignore all assets outside of html requests (which don't have an extension)
3744
// so could we just check any request that doesn't have an extension?
45+
const requestUrl = new URL(req.url);
3846
if (
39-
req.url.startsWith("/_next") ||
40-
req.url.match(
47+
// ignore healthcheck because it's for automated test suite that can't do redirects
48+
requestUrl.pathname.startsWith("/healthcheck") ||
49+
requestUrl.pathname.startsWith("/_next") ||
50+
requestUrl.pathname.match(
4151
/\.(js|css|png|jpg|jpeg|svg|gif|ico|json|woff|woff2|ttf|eot|otf)$/
4252
)
4353
) {
4454
return undefined;
4555
}
4656

47-
const { cookies } = req;
48-
const hasCsrfToken = cookies.has("csrftoken");
49-
if (hasCsrfToken) {
50-
return undefined;
51-
}
52-
5357
const csrfUrl = `${apiBaseUrl}/csrf/`;
5458
const redirectUrl = new URL(csrfUrl);
55-
const requestUrl = new URL(req.url);
5659

5760
// On server envs everything is in the same domain and 80/443 ports, so ignore the host part of the url.
5861
// More robust solution (supporting separate domains) would need to take into account us being behind

apps/ui/pages/healthcheck.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { type GetServerSidePropsContext } from "next";
2+
import { serverSideTranslations } from "next-i18next/serverSideTranslations";
3+
import Head from "next/head";
4+
5+
/* Separate healthcheck page that does no GraphQL queries to avoid csrf token issues */
6+
export default function Index() {
7+
return (
8+
<>
9+
<Head>
10+
<meta name="robots" content="noindex,nofollow" />
11+
</Head>
12+
<div>Healthcheck</div>
13+
</>
14+
);
15+
}
16+
17+
export async function getServerSideProps({
18+
locale,
19+
}: GetServerSidePropsContext) {
20+
return {
21+
props: {
22+
...(await serverSideTranslations(locale ?? "fi")),
23+
},
24+
};
25+
}

0 commit comments

Comments
 (0)