from django.contrib import admin from django.conf import settings from django.conf.urls.static import static from django.db import connection from django.http import JsonResponse from django.shortcuts import render from django.templatetags.static import static as static_url from django.urls import include, path from django.views.static import serve from apps.core.models import SiteBranding def healthz(request): with connection.cursor() as cursor: cursor.execute("SELECT 1") cursor.fetchone() response = JsonResponse({"status": "ok"}) response["Cache-Control"] = "no-store" return response def public_branding(request, path): """Serve only public branding uploads; all ticket files use authorized views.""" return serve(request, path, document_root=settings.MEDIA_ROOT / "branding") def service_worker(request): response = render(request, "pwa/service-worker.js", content_type="application/javascript") response["Cache-Control"] = "no-cache, no-store, must-revalidate" response["Service-Worker-Allowed"] = "/" return response def web_manifest(request): branding = SiteBranding.load() try: icon_url = branding.pwa_icon.url if branding.pwa_icon else static_url("images/pwa-icon.png") except (ValueError, OSError): icon_url = static_url("images/pwa-icon.png") response = JsonResponse({ "id": "/", "name": branding.pwa_name, "short_name": branding.pwa_title, "description": branding.pwa_description, "start_url": "/tickets/", "scope": "/", "display": "standalone", "background_color": "#eeeeee", "theme_color": "#08376b", "lang": "fa", "dir": "rtl", "icons": [{"src": icon_url, "sizes": "1024x1024", "type": "image/png", "purpose": "any maskable"}], }, json_dumps_params={"ensure_ascii": False}) response["Cache-Control"] = "no-cache, no-store, must-revalidate" return response urlpatterns = [ path("healthz/", healthz, name="healthz"), path("media/branding/", public_branding, name="public_branding"), path("service-worker.js", service_worker, name="service_worker"), path("manifest.webmanifest", web_manifest, name="web_manifest"), path("admin/", admin.site.urls), path("", include("apps.accounts.urls")), path("tickets/", include("apps.tickets.customer_urls")), path("staff/", include("apps.tickets.staff_urls")), path("messages/", include("apps.messaging.urls")), path("files/", include("apps.attachments.urls")), ] if settings.DEBUG: urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)