-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
57 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
from django.contrib import admin | ||
from django.http import HttpResponse | ||
from django.shortcuts import render | ||
from django.urls import include, path, re_path | ||
from rest_framework import status | ||
|
||
from .settings import SERVICE_IS_ROOT, SERVICE_NAME | ||
|
||
|
||
def service_urlpatterns( | ||
api_urls_path: str = "api.urls", | ||
frontend_template_name: str = "frontend.html", | ||
): | ||
urlpatterns = [ | ||
path( | ||
"admin/", | ||
admin.site.urls, | ||
name="admin", | ||
), | ||
path( | ||
"api/", | ||
include(api_urls_path), | ||
name="api", | ||
), | ||
re_path( | ||
r"^api/.*", | ||
lambda request: HttpResponse( | ||
"API endpoint not found", | ||
status=status.HTTP_404_NOT_FOUND, | ||
), | ||
name="api-endpoint-not-found", | ||
), | ||
re_path( | ||
r".*", | ||
lambda request: render(request, frontend_template_name), | ||
name="frontend", | ||
), | ||
] | ||
|
||
if SERVICE_IS_ROOT: | ||
return urlpatterns | ||
|
||
return [ | ||
path( | ||
f"{SERVICE_NAME}/", | ||
include(urlpatterns), | ||
name="service", | ||
), | ||
re_path( | ||
r".*", | ||
lambda request: HttpResponse( | ||
f'The base route is "{SERVICE_NAME}/".', | ||
status=status.HTTP_404_NOT_FOUND, | ||
), | ||
name="service-not-found", | ||
), | ||
] |