From 1a60694112a709312b801c2435b249513efdca5d Mon Sep 17 00:00:00 2001 From: Quantum Date: Thu, 2 Jan 2025 01:08:10 -0500 Subject: [PATCH] Add health check endpoint --- qlinks/urls/short.py | 3 ++- qlinks/views.py | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/qlinks/urls/short.py b/qlinks/urls/short.py index 952c7e2..f9299af 100644 --- a/qlinks/urls/short.py +++ b/qlinks/urls/short.py @@ -2,9 +2,10 @@ from django.urls import path -from qlinks.views import short_link +from qlinks.views import health_check, short_link urlpatterns = [ path('', partial(short_link, path=''), name='short_link'), + path('api/health_check', health_check, name='health_check'), path('', short_link, name='short_link'), ] diff --git a/qlinks/views.py b/qlinks/views.py index 061477c..81f78ee 100644 --- a/qlinks/views.py +++ b/qlinks/views.py @@ -1,5 +1,5 @@ from django.conf import settings -from django.http import HttpResponseRedirect +from django.http import HttpResponse, HttpResponseRedirect from django.shortcuts import get_object_or_404 from qlinks.models import Link @@ -10,3 +10,8 @@ def short_link(request, path): return HttpResponseRedirect(link, headers={ 'X-Powered-By': settings.QLINKS_POWERED_BY }) + + +def health_check(request): + Link.objects.exists() + return HttpResponse('qlinks seems to work!')