File size: 869 Bytes
cb5f524
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0b4eacc
 
 
cb5f524
0b4eacc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from django.conf import settings
from django.http import FileResponse, Http404
from django.urls import include, path, re_path


def spa_index(_request):
    """Serve the SPA shell for any non-API path.

    WhiteNoise serves real files from ``SPA_DIST_DIR`` (assets, favicon, …)
    before URL routing, so this view only fires for client-side routes such
    as ``/cv``, ``/demos/coins`` or unknown paths — Vue Router picks them up
    on the client (the wildcard route renders the Lara Croft 404).
    """
    index = settings.SPA_DIST_DIR / "index.html"
    if not index.exists():
        raise Http404("SPA build is missing — run `npm run build` in src/frontend first")
    return FileResponse(open(index, "rb"), content_type="text/html")


urlpatterns = [
    path("api/v1/", include("api.urls")),
    re_path(r"^(?!api/).*$", spa_index, name="spa-index"),
]