Skip to content

fix(client): rewrite absolute fetch/EventSource paths under basePath - #8515

Merged
diegosouzapw merged 7 commits into
cheaper-inference:release/v3.8.49from
rqzbeh:fix/basepath-client-fetch
Jul 28, 2026
Merged

diegosouzapw merged 7 commits into
cheaper-inference:release/v3.8.49from
rqzbeh:fix/basepath-client-fetch

Conversation

@rqzbeh

@rqzbeh rqzbeh commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Summary

When OmniRoute is served under a reverse-proxy subpath (OMNIROUTE_BASE_PATH=/omniroute), absolute client calls:

fetch("/api/health/ping")
new EventSource("/api/services/bifrost/logs")

hit https://host/api/... instead of https://host/omniroute/api/....

That breaks the maintenance banner, dashboard APIs, SSE log streams, and login bootstrap unless nginx rewrites /api and /v1 at the edge.

Next.js rewrites Link / useRouter for basePath, but not the Fetch / EventSource APIs.

Approach

Mirror the existing installDashboardCsrfFetch pattern:

  1. withBasePath() — pure helper for absolute paths and same-origin absolute URLs
  2. installBasePathFetch() — ref-counted wrap of globalThis.fetch + window.EventSource when basePath is non-empty (no-op on root deploys)
  3. BasePathNetworkProvider mounted in the root layout (covers login + dashboard)
  4. Dashboard layout also installs (composes with CSRF: basePath wraps native first)
  5. next.config.mjs mirrors OMNIROUTE_BASE_PATH → NEXT_PUBLIC_OMNIROUTE_BASE_PATH for the client bundle

No authz changes. Root deploys unchanged (empty basePath → install is a no-op).

Related

Test plan

  • Root deploy (no basePath): no behavior change; health/dashboard work as today
  • Subpath deploy with rebuild (OMNIROUTE_BASE_PATH=/omniroute):
    • Login works without nginx /api rewrite
    • Maintenance banner stops false-positive “server issues”
    • Dashboard settings/providers/services SSE logs load
    • CSRF mutations still work (install order: basePath then CSRF)
  • vitest run src/shared/utils/__tests__/basePath.test.ts src/shared/utils/__tests__/basePathFetch.test.ts

Absolute browser calls like fetch("/api/...") and new EventSource("/api/...")
do not honor Next.js basePath, so subpath deploys (OMNIROUTE_BASE_PATH) break
dashboard health checks, settings APIs, and SSE unless a reverse proxy rewrites
the domain root.

- Add withBasePath / getDeployBasePath helpers
- Install ref-counted fetch + EventSource rewrite when basePath is set
  (same pattern as installDashboardCsrfFetch)
- Mount BasePathNetworkProvider at the root so login works too
- Mirror OMNIROUTE_BASE_PATH to NEXT_PUBLIC_OMNIROUTE_BASE_PATH for the client
- Document in .env.example; unit tests for rewrite rules
@rqzbeh
rqzbeh requested a review from diegosouzapw as a code owner July 25, 2026 02:36
rqzbeh and others added 6 commits July 25, 2026 06:14
…ll-shape asserts

Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
…et and fix basePath TS2322

Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
@diegosouzapw
diegosouzapw merged commit 8e5dc0d into cheaper-inference:release/v3.8.49 Jul 28, 2026
5 checks passed
@diegosouzapw diegosouzapw mentioned this pull request Jul 28, 2026
HouMinXi pushed a commit to HouMinXi/OmniRoute that referenced this pull request Aug 2, 2026
…heaper-inference#8515)

* fix(client): rewrite absolute fetch/EventSource paths under basePath

Absolute browser calls like fetch("/api/...") and new EventSource("/api/...")
do not honor Next.js basePath, so subpath deploys (OMNIROUTE_BASE_PATH) break
dashboard health checks, settings APIs, and SSE unless a reverse proxy rewrites
the domain root.

- Add withBasePath / getDeployBasePath helpers
- Install ref-counted fetch + EventSource rewrite when basePath is set
  (same pattern as installDashboardCsrfFetch)
- Mount BasePathNetworkProvider at the root so login works too
- Mirror OMNIROUTE_BASE_PATH to NEXT_PUBLIC_OMNIROUTE_BASE_PATH for the client
- Document in .env.example; unit tests for rewrite rules

* docs(changelog): add fragment for cheaper-inference#8515 basePath client fetch

* test(client): move basePath tests into a scanned dir and fix no-op call-shape asserts

Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>

* fix(client-sweep-8515): restore CHANGELOG cheaper-inference#8471 bullet and fix basePath TS2322

Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>

---------

Co-authored-by: rqzbeh <rqzbeh@users.noreply.github.com>
Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
Co-authored-by: Diego Rodrigues de Sa e Souza <diegosouza.pw@gmail.com>
Co-authored-by: diegosouzapw <diegosouzapw@users.noreply.github.com>
muhamadgalihsaputra pushed a commit to niyatna/NiyatnaRoute that referenced this pull request Sep 27, 2026
…heaper-inference#8515)

* fix(client): rewrite absolute fetch/EventSource paths under basePath

Absolute browser calls like fetch("/api/...") and new EventSource("/api/...")
do not honor Next.js basePath, so subpath deploys (OMNIROUTE_BASE_PATH) break
dashboard health checks, settings APIs, and SSE unless a reverse proxy rewrites
the domain root.

- Add withBasePath / getDeployBasePath helpers
- Install ref-counted fetch + EventSource rewrite when basePath is set
  (same pattern as installDashboardCsrfFetch)
- Mount BasePathNetworkProvider at the root so login works too
- Mirror OMNIROUTE_BASE_PATH to NEXT_PUBLIC_OMNIROUTE_BASE_PATH for the client
- Document in .env.example; unit tests for rewrite rules

* docs(changelog): add fragment for cheaper-inference#8515 basePath client fetch

* test(client): move basePath tests into a scanned dir and fix no-op call-shape asserts

Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>

* fix(client-sweep-8515): restore CHANGELOG cheaper-inference#8471 bullet and fix basePath TS2322

Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>

---------

Co-authored-by: rqzbeh <rqzbeh@users.noreply.github.com>
Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
Co-authored-by: Diego Rodrigues de Sa e Souza <diegosouza.pw@gmail.com>
Co-authored-by: diegosouzapw <diegosouzapw@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants