Skip to content

Commit

Permalink
add: devops / kubernetes health check pages
Browse files Browse the repository at this point in the history
  • Loading branch information
joonatank committed Apr 24, 2024
1 parent 67b0e86 commit fc92e60
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 10 deletions.
16 changes: 16 additions & 0 deletions apps/admin-ui/src/pages/healthcheck.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import Head from "next/head";
import Layout from "./layout";

/* Separate healthcheck page that does no GraphQL queries to avoid csrf token issues */
export default function Index() {
return (
<>
<Head>
<meta name="robots" content="noindex,nofollow" />
</Head>
<Layout>
<div>Healthcheck</div>
</Layout>
</>
);
}
23 changes: 13 additions & 10 deletions apps/ui/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,31 @@ function redirectProtectedRoute(req: NextRequest) {
return undefined;
}

/// are we missing a csrf token in cookies and should redirect to get one
/// are we missing a csrf token in cookies
/// if so get the backend url to redirect to and add the current url as a redirect_to parameter
function redirectCsrfToken(req: NextRequest): URL | undefined {
const { cookies } = req;
const hasCsrfToken = cookies.has("csrftoken");
if (hasCsrfToken) {
return undefined;
}

// need to ignore all assets outside of html requests (which don't have an extension)
// so could we just check any request that doesn't have an extension?
const requestUrl = new URL(req.url);
if (
req.url.startsWith("/_next") ||
req.url.match(
// ignore healthcheck because it's for automated test suite that can't do redirects
requestUrl.pathname.startsWith("/healthcheck") ||
requestUrl.pathname.startsWith("/_next") ||
requestUrl.pathname.match(
/\.(js|css|png|jpg|jpeg|svg|gif|ico|json|woff|woff2|ttf|eot|otf)$/
)
) {
return undefined;
}

const { cookies } = req;
const hasCsrfToken = cookies.has("csrftoken");
if (hasCsrfToken) {
return undefined;
}

const csrfUrl = `${apiBaseUrl}/csrf/`;
const redirectUrl = new URL(csrfUrl);
const requestUrl = new URL(req.url);

// On server envs everything is in the same domain and 80/443 ports, so ignore the host part of the url.
// More robust solution (supporting separate domains) would need to take into account us being behind
Expand Down
25 changes: 25 additions & 0 deletions apps/ui/pages/healthcheck.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { type GetServerSidePropsContext } from "next";
import { serverSideTranslations } from "next-i18next/serverSideTranslations";
import Head from "next/head";

/* Separate healthcheck page that does no GraphQL queries to avoid csrf token issues */
export default function Index() {
return (
<>
<Head>
<meta name="robots" content="noindex,nofollow" />
</Head>
<div>Healthcheck</div>
</>
);
}

export async function getServerSideProps({
locale,
}: GetServerSidePropsContext) {
return {
props: {
...(await serverSideTranslations(locale ?? "fi")),
},
};
}

0 comments on commit fc92e60

Please sign in to comment.