tannuiscoding commited on
Commit
b2ffd25
·
1 Parent(s): ade280d

Fix API base path for Hugging Face Spaces nested routes

Browse files
Files changed (1) hide show
  1. frontend/src/api/client.js +13 -2
frontend/src/api/client.js CHANGED
@@ -1,7 +1,18 @@
1
- const BASE = '' // same-origin in prod; Vite proxy handles /api in dev
 
 
 
 
 
 
 
 
 
 
2
 
3
  async function request(path, options = {}) {
4
- const res = await fetch(BASE + path, {
 
5
  credentials: 'include',
6
  headers: { 'Content-Type': 'application/json', ...(options.headers || {}) },
7
  ...options,
 
1
+ const BASE = (() => {
2
+ if (typeof window === 'undefined') return ''
3
+ const pathname = window.location.pathname
4
+ if (pathname.startsWith('/spaces/')) {
5
+ const parts = pathname.split('/').filter(Boolean)
6
+ if (parts.length >= 3) {
7
+ return `/${parts.slice(0, 3).join('/')}`
8
+ }
9
+ }
10
+ return ''
11
+ })()
12
 
13
  async function request(path, options = {}) {
14
+ const url = path.startsWith('/') ? `${BASE}${path}` : `${BASE}/${path}`
15
+ const res = await fetch(url, {
16
  credentials: 'include',
17
  headers: { 'Content-Type': 'application/json', ...(options.headers || {}) },
18
  ...options,