Add health check endpoint

This commit is contained in:
Quantum 2025-01-02 01:08:10 -05:00
parent 7ff577fd0c
commit 1a60694112
2 changed files with 8 additions and 2 deletions

View file

@ -2,9 +2,10 @@ from functools import partial
from django.urls import path from django.urls import path
from qlinks.views import short_link from qlinks.views import health_check, short_link
urlpatterns = [ urlpatterns = [
path('', partial(short_link, path=''), name='short_link'), path('', partial(short_link, path=''), name='short_link'),
path('api/health_check', health_check, name='health_check'),
path('<path:path>', short_link, name='short_link'), path('<path:path>', short_link, name='short_link'),
] ]

View file

@ -1,5 +1,5 @@
from django.conf import settings 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 django.shortcuts import get_object_or_404
from qlinks.models import Link from qlinks.models import Link
@ -10,3 +10,8 @@ def short_link(request, path):
return HttpResponseRedirect(link, headers={ return HttpResponseRedirect(link, headers={
'X-Powered-By': settings.QLINKS_POWERED_BY 'X-Powered-By': settings.QLINKS_POWERED_BY
}) })
def health_check(request):
Link.objects.exists()
return HttpResponse('qlinks seems to work!')