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(); 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: "/", 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; }