Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions client/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 "/<subpath>/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();
Expand Down
6 changes: 2 additions & 4 deletions client/src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 "/<subpath>/"
history: createWebHistory(import.meta.env.BASE_URL),
routes: [
{
path: "/",
Expand Down
5 changes: 3 additions & 2 deletions prod/nginx/nginx.subpath.nominio.template
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
5 changes: 3 additions & 2 deletions prod/nginx/nginx.subpath.template
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down