from django.contrib import admin from django.urls import path, include from drf_spectacular.views import SpectacularAPIView, SpectacularRedocView, SpectacularSwaggerView from rest_framework.authtoken.views import obtain_auth_token from django.conf import settings from django.conf.urls.static import static from django.views.static import serve from django.views.generic.base import TemplateView from django.http import HttpResponse import os def health_check(request): return HttpResponse("OK", content_type="text/plain") # Clean the admin path admin_url = os.environ.get('ADMIN_URL', 'admin').strip('/') urlpatterns = [ # Health check path('health/', health_check, name='health_check'), # Robots.txt path('robots.txt', TemplateView.as_view(template_name="robots.txt", content_type="text/plain")), # Ensure admin ends with a slash for Django's redirection logic path(f'{admin_url}/', admin.site.urls), path('api/', include('api.urls')), path('api/token/', obtain_auth_token, name='api_token'), path('api-auth/', include('rest_framework.urls')), path('api/schema/', SpectacularAPIView.as_view(), name='schema'), path('api/schema/swagger-ui/', SpectacularSwaggerView.as_view(url_name='schema'), name='swagger-ui'), path('api/schema/redoc/', SpectacularRedocView.as_view(url_name='schema'), name='redoc'), path('media/', serve, {'document_root': settings.MEDIA_ROOT}), ]