Skip to content
Merged
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
11 changes: 11 additions & 0 deletions backend/Platform/middleware.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from django.http import HttpResponse


class HealthCheckMiddleware:
def __init__(self, get_response):
self.get_response = get_response

def __call__(self, request):
if request.path == "/health":
return HttpResponse("ok")
return self.get_response(request)
1 change: 1 addition & 0 deletions backend/Platform/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
path("accounts/", include("accounts.urls", namespace="oauth2_provider")),
path("options/", include("options.urls", namespace="options")),
path("identity/", include("identity.urls", namespace="identity")),
path("healthcheck/", include("health.urls", namespace="healthcheck")),
path("s/", include("shortener.urls", namespace="shortener")),
path(
"openapi/",
Expand Down
5 changes: 5 additions & 0 deletions backend/health/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class HealthConfig(AppConfig):
name = "health"
5 changes: 5 additions & 0 deletions backend/health/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class HealthConfig(AppConfig):
name = "health"
9 changes: 9 additions & 0 deletions backend/health/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.urls import path
from health.views import HealthView


app_name = "health"

urlpatterns = [
path("backend/", HealthView.as_view(), name="backend"),
]
25 changes: 25 additions & 0 deletions backend/health/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from http import HTTPStatus

from django.http import JsonResponse
from django.views.generic import View


class HealthView(View):
def get(self, request):
"""
Health check endpoint to confirm the backend is running.
---
summary: Health Check
responses:
"200":
content:
application/json:
schema:
type: object
properties:
message:
type: string
enum: ["OK"]
---
"""
return JsonResponse({"message": "OK"}, status=HTTPStatus.OK)
11 changes: 11 additions & 0 deletions backend/tests/identity/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,14 @@ def test_garbage_bearer(self):
self.assertIsInstance(content, dict)
self.assertEqual(HTTPStatus.BAD_REQUEST, response.status_code)
self.assertNotIn("access", content)


class HealthTestCase(TestCase):
def setUp(self):
self.client = Client()

def test_health(self):
url = reverse("healthcheck:backend")
resp = self.client.get(url)
self.assertEqual(resp.status_code, 200)
self.assertEqual(resp.json(), {"message": "OK"})
9 changes: 4 additions & 5 deletions frontend/components/accounts/modals/verification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Modal } from "react-bulma-components";

import { mutateResourceListFunction } from "@pennlabs/rest-hooks/dist/types";
import toast from "react-hot-toast";
import styles from "../../../styles/Verification.module.css";
import { verifyContact } from "../../../data-fetching/accounts";
import { ContactType, ContactInfo } from "../../../types";
import { logException } from "../../../utils/sentry";
Expand Down Expand Up @@ -38,9 +37,9 @@ const VerificationForm = (props: VerificationFormProps) => {
onChange={handleInputChange}
validChars="0-9"
classNames={{
container: styles.container,
character: styles.character,
characterSelected: styles["character--selected"],
container: "verification-modal-container",
character: "verification-modal-character",
characterSelected: "verification-modal-character-selected",
}}
removeDefaultStyles
/>
Expand All @@ -59,7 +58,7 @@ const VerificationModal = (props: VerificationModalProps) => {
const { show, closeFunc, type, contact, id, mutate } = props;
const prettyType = type === ContactType.Email ? "Email" : "Phone Number";
return (
<Modal show={show} onClose={closeFunc}>
<Modal show={show} onClose={closeFunc} className="verification-modal">
<Modal.Card>
<Modal.Card.Header onClose={closeFunc}>
<Modal.Card.Title>
Expand Down
5 changes: 4 additions & 1 deletion frontend/next-env.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
/// <reference types="next" />
/// <reference types="next/types/global" />
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/pages/api-reference/config/typescript for more information.
1 change: 1 addition & 0 deletions frontend/pages/_app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import "bulma/css/bulma.min.css";
import "../styles/globals.css";
import "../styles/Verification.module.css";

const MyApp = ({ Component, pageProps }) => {
return <Component {...pageProps} />;
Expand Down
24 changes: 24 additions & 0 deletions frontend/pages/health.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { GetServerSideProps } from "next";

const HealthPage = () => {
return <div>OK</div>;
};

export const getServerSideProps: GetServerSideProps = async ({ req }) => {
const userAgent = req.headers["user-agent"] || "";

if (userAgent !== "service-status") {
return {
redirect: {
destination: "/",
permanent: false,
},
};
}

return {
props: {},
};
};

export default HealthPage;
10 changes: 5 additions & 5 deletions frontend/styles/Verification.module.css
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
.container {
.verification-modal-container {
height: 50px;
width: 300px;
margin-top: 10px;
}

.character {
.verification-modal-character {
line-height: 50px;
font-size: 36px;
color: black;
Expand All @@ -14,10 +14,10 @@
margin-left: 8px;
}

.character:first-child {
.verification-modal-character:first-child {
margin-left: 0;
}

.character--selected {
.verification-modal-character-selected {
border: 1px solid #b0b0b0;
}
}
3 changes: 2 additions & 1 deletion frontend/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx"
"**/*.tsx",
"**/*.css"
]
}
17 changes: 16 additions & 1 deletion frontend/utils/auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { doApiRequest } from "./fetch";
import { User } from "../types";

export interface AuthProps {
user: User;
user: User | null;
}

type GetServerSidePropsResultDiscUnion<T> =
Expand Down Expand Up @@ -39,6 +39,21 @@ export function withAuth<T>(getServerSidePropsFunc: GetServerSidePropsFunc<T>) {
return async (
ctx: GetServerSidePropsContext
): Promise<GetServerSidePropsResult<T & AuthProps>> => {
if (ctx.resolvedUrl === "/health") {
const wrapped = await getServerSidePropsFunc(ctx);
const casted = convertGetServerSidePropsResult(wrapped);

if (casted.tag === "props") {
return {
props: { ...casted.props, user: null } as T & AuthProps,
};
} else if (casted.tag === "notFound") {
return { notFound: casted.notFound };
} else {
return { redirect: casted.redirect };
}
}

const headers = {
credentials: "include",
headers: { cookie: ctx.req.headers.cookie },
Expand Down
2 changes: 2 additions & 0 deletions k8s/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ export class MyChart extends PennLabsChart {
"/openapi",
"/documentation",
"/Shibboleth.sso",
"/healthcheck",
],
isSubdomain: true,
}],

ingressProps: {
annotations: {
["ingress.kubernetes.io/protocol"]: "https",
Expand Down
Loading