Skip to content

Commit 7627e84

Browse files
committed
health
1 parent 524282d commit 7627e84

File tree

4 files changed

+56
-0
lines changed

4 files changed

+56
-0
lines changed

backend/ohq/urls.py

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
SemesterViewSet,
2020
TagViewSet,
2121
UserView,
22+
HealthView,
2223
)
2324

2425

@@ -45,6 +46,7 @@
4546
realtime_router.register(AnnouncementViewSet)
4647

4748
additional_urls = [
49+
path("health/", HealthView.as_view(), name="health"),
4850
path("accounts/me/", UserView.as_view(), name="me"),
4951
path("accounts/me/resend/", ResendNotificationView.as_view(), name="resend"),
5052
path("courses/<slug:course_pk>/mass-invite/", MassInviteView.as_view(), name="mass-invite"),

backend/ohq/views.py

+21
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
Subquery,
1717
When,
1818
)
19+
from django.views.generic import View
1920
from django.http import HttpResponseBadRequest, JsonResponse
2021
from django.utils import timezone
2122
from django.utils.crypto import get_random_string
@@ -32,6 +33,7 @@
3233
from rest_framework.views import APIView
3334
from rest_live.mixins import RealtimeMixin
3435
from schedule.models import Event, EventRelationManager, Occurrence
36+
from http import HTTPStatus
3537

3638
from ohq.filters import CourseStatisticFilter, QuestionSearchFilter, QueueStatisticFilter
3739
from ohq.invite import parse_and_send_invites
@@ -775,3 +777,22 @@ def list(self, request, *args, **kwargs):
775777

776778
def get_queryset(self):
777779
return Occurrence.objects.filter(pk=self.kwargs["pk"])
780+
class HealthView(View):
781+
def get(self, request):
782+
"""
783+
Health check endpoint to confirm the backend is running.
784+
---
785+
summary: Health Check
786+
responses:
787+
"200":
788+
content:
789+
application/json:
790+
schema:
791+
type: object
792+
properties:
793+
message:
794+
type: string
795+
enum: ["OK"]
796+
---
797+
"""
798+
return JsonResponse({"message": "OK"}, status=HTTPStatus.OK)

backend/tests/ohq/test_health.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from django.test import TestCase
2+
from django.urls import reverse
3+
4+
class HealthTestCase(TestCase):
5+
def test_health(self):
6+
url = reverse("health")
7+
resp = self.client.get(url)
8+
self.assertEqual(resp.status_code, 200)
9+
self.assertEqual(resp.data, {"message": "OK"})

frontend/pages/health.tsx

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { GetServerSideProps } from 'next';
2+
3+
const HealthPage = () => {
4+
return <div>OK</div>;
5+
};
6+
7+
export const getServerSideProps: GetServerSideProps = async ({ req }) => {
8+
const userAgent = req.headers['user-agent'] || '';
9+
10+
if (userAgent !== 'service-status') {
11+
return {
12+
redirect: {
13+
destination: '/',
14+
permanent: false,
15+
},
16+
};
17+
}
18+
19+
return {
20+
props: {},
21+
};
22+
};
23+
24+
export default HealthPage;

0 commit comments

Comments
 (0)