diff --git a/backend/health/__init__.py b/backend/health/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/backend/health/apps.py b/backend/health/apps.py new file mode 100644 index 00000000..e860540e --- /dev/null +++ b/backend/health/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class HealthConfig(AppConfig): + name = "health" diff --git a/backend/health/urls.py b/backend/health/urls.py new file mode 100644 index 00000000..68352e21 --- /dev/null +++ b/backend/health/urls.py @@ -0,0 +1,10 @@ +from django.urls import path + +from health.views import HealthView + + +app_name = "health" + +urlpatterns = [ + path("health/", HealthView.as_view(), name="health"), +] diff --git a/backend/health/views.py b/backend/health/views.py new file mode 100644 index 00000000..ba5bb8f2 --- /dev/null +++ b/backend/health/views.py @@ -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) diff --git a/backend/pennmobile/settings/base.py b/backend/pennmobile/settings/base.py index e2bc3154..34906c16 100644 --- a/backend/pennmobile/settings/base.py +++ b/backend/pennmobile/settings/base.py @@ -54,6 +54,7 @@ "options.apps.OptionsConfig", "sublet", "phonenumber_field", + "health", ] MIDDLEWARE = [ diff --git a/backend/pennmobile/urls.py b/backend/pennmobile/urls.py index f517a8af..a67e6ddb 100644 --- a/backend/pennmobile/urls.py +++ b/backend/pennmobile/urls.py @@ -28,6 +28,7 @@ path("penndata/", include("penndata.urls")), path("sublet/", include("sublet.urls")), path("wrapped/", include("wrapped.urls")), + path("", include("health.urls")), ] urlpatterns = [ diff --git a/backend/tests/health/__init__.py b/backend/tests/health/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/backend/tests/health/test_route.py b/backend/tests/health/test_route.py new file mode 100644 index 00000000..445bb86c --- /dev/null +++ b/backend/tests/health/test_route.py @@ -0,0 +1,8 @@ +from django.test import TestCase + + +class HealthTestCase(TestCase): + def test_health(self): + resp = self.client.get("/health/") + self.assertEqual(resp.status_code, 200) + self.assertEqual(resp.json(), {"message": "OK"})