add health API endpoint, #887

This commit is contained in:
Simon 2025-03-11 22:10:17 +07:00
parent e06e1be433
commit 862a854e64
4 changed files with 14 additions and 12 deletions

View File

@ -1,11 +0,0 @@
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)

View File

@ -25,4 +25,9 @@ urlpatterns = [
views.NotificationView.as_view(),
name="api-notification",
),
path(
"health/",
views.HealthCheck.as_view(),
name="api-health",
),
]

View File

@ -20,6 +20,7 @@ from common.src.watched import WatchState
from common.views_base import AdminOnly, ApiBaseView
from drf_spectacular.utils import OpenApiResponse, extend_schema
from rest_framework.response import Response
from rest_framework.views import APIView
from task.tasks import check_reindex
@ -199,3 +200,11 @@ class NotificationView(ApiBaseView):
response_serializer = NotificationSerializer(notifications, many=True)
return Response(response_serializer.data)
class HealthCheck(APIView):
"""health check view, no auth needed"""
def get(self, request):
"""health check, no auth needed"""
return Response("OK", status=200)

View File

@ -82,7 +82,6 @@ MIDDLEWARE = [
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"common.src.health.HealthCheckMiddleware",
]
ROOT_URLCONF = "config.urls"