From 70d598180f48a1f907ee44ed03bdbbab7d768652 Mon Sep 17 00:00:00 2001 From: naglepuff Date: Thu, 12 Nov 2026 14:08:57 -0500 Subject: [PATCH 1/3] Fix nginx proxying to django for subpaths --- prod/nginx/nginx.subpath.nominio.template | 5 +++-- prod/nginx/nginx.subpath.template | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/prod/nginx/nginx.subpath.nominio.template b/prod/nginx/nginx.subpath.nominio.template index ff8a69fe..12a7b9a1 100644 --- a/prod/nginx/nginx.subpath.nominio.template +++ b/prod/nginx/nginx.subpath.nominio.template @@ -21,13 +21,14 @@ http { # Proxy Django paths with all necessary headers location ~ ^/${DJANGO_BATAI_URL_PATH}/(api|oauth|static|admin|accounts) { + # Django resolves URLs against PATH_INFO; FORCE_SCRIPT_NAME only affects URL + # generation, so strip the subpath before proxying. + rewrite ^/${DJANGO_BATAI_URL_PATH}/(.*)$ /$1 break; proxy_pass http://django:8000; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; - # Required for Django subpath handling (especially admin) - proxy_set_header X-SCRIPT-NAME /${DJANGO_BATAI_URL_PATH}/; proxy_redirect off; } diff --git a/prod/nginx/nginx.subpath.template b/prod/nginx/nginx.subpath.template index bbb354cc..f6ac40f9 100644 --- a/prod/nginx/nginx.subpath.template +++ b/prod/nginx/nginx.subpath.template @@ -21,13 +21,14 @@ http { # Proxy Django paths with all necessary headers location ~ ^/${DJANGO_BATAI_URL_PATH}/(api|oauth|static|admin|accounts) { + # Django resolves URLs against PATH_INFO; FORCE_SCRIPT_NAME only affects URL + # generation, so strip the subpath before proxying. + rewrite ^/${DJANGO_BATAI_URL_PATH}/(.*)$ /$1 break; proxy_pass http://django:8000; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; - # Required for Django subpath handling (especially admin) - proxy_set_header X-SCRIPT-NAME /${DJANGO_BATAI_URL_PATH}/; proxy_redirect off; } From 57758aaf70ced4f240e5d85b76597ef209e5efe6 Mon Sep 17 00:00:00 2001 From: naglepuff Date: Thu, 12 Nov 2026 14:09:55 -0500 Subject: [PATCH 2/3] Strip subpath when checking nabat routes --- client/src/main.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/client/src/main.ts b/client/src/main.ts index 0582eda1..6bb1be42 100644 --- a/client/src/main.ts +++ b/client/src/main.ts @@ -39,9 +39,14 @@ Sentry.init({ // its own `code`/`state` query params, unrelated to this app's login. oauth-client's // maybeRestoreLogin() strips those from the URL unconditionally, assuming they're its own // callback, so skip it entirely on this one route - it doesn't rely on this app's OAuth anyway. -const isNabatRecordingEntrypoint = NABAT_ENTRYPOINT_PATH_REGEX.test( - window.location.pathname, -); +// The regex matches router-relative paths ("/nabat/auth/"), but under a subpath deployment +// window.location.pathname is "//nabat/auth/", so strip the app base first. +const appBase = import.meta.env.BASE_URL; +const { pathname } = window.location; +const routerPath = pathname.startsWith(appBase) + ? `/${pathname.slice(appBase.length)}` + : pathname; +const isNabatRecordingEntrypoint = NABAT_ENTRYPOINT_PATH_REGEX.test(routerPath); const restoreLogin = isNabatRecordingEntrypoint ? Promise.resolve() : maybeRestoreLogin(); From 9d5fa68ec8d03e1e9b5d8f09a856a6679a8311c1 Mon Sep 17 00:00:00 2001 From: naglepuff Date: Thu, 12 Nov 2026 14:10:10 -0500 Subject: [PATCH 3/3] Prevent router base path from starting with "//" --- client/src/router/index.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/client/src/router/index.ts b/client/src/router/index.ts index b7f92555..fd35ecbc 100644 --- a/client/src/router/index.ts +++ b/client/src/router/index.ts @@ -39,12 +39,10 @@ function beforeEach( // Explicitly return for clarity, though returning nothing also works return; } -const subpath = import.meta.env.VITE_SUBPATH?.replace(/\/+$/, ""); -const routerBase = subpath ? `/${subpath}/` : "/"; - function routerInit() { const router = createRouter({ - history: createWebHistory(routerBase), + // Vite's `base` (derived from VITE_SUBPATH in vite.config.ts), normalized to "//" + history: createWebHistory(import.meta.env.BASE_URL), routes: [ { path: "/",