Spaces:
Running on Zero
Running on Zero
fix: use getApiUrl in frontend for direct cross-origin API calls without proxy payload stripping
d585643 Download frontend/lib/api.ts from muhammadpriv001/Object-Intelligence-Backend: direct link, hf CLI and curl.
- Browser
- Download file 669 Bytes
-
https://huggingface.co/spaces/muhammadpriv001/Object-Intelligence-Backend/resolve/main/frontend/lib/api.ts
- Command line
-
hf download hf://spaces/muhammadpriv001/Object-Intelligence-Backend/frontend/lib/api.ts
-
curl -L -o api.ts https://huggingface.co/spaces/muhammadpriv001/Object-Intelligence-Backend/resolve/main/frontend/lib/api.ts
669 Bytes
| export function getApiUrl(path: string): string { | |
| const envUrl = process.env.NEXT_PUBLIC_API_URL || ""; | |
| const cleanBase = envUrl.trim().replace(/\/+$/, ""); | |
| const cleanPath = path.startsWith("/") ? path : `/${path}`; | |
| if (cleanBase) { | |
| // Direct cross-origin request to backend (bypasses Next.js proxy body mangling) | |
| const apiPrefix = cleanPath.startsWith("/api") ? cleanPath : `/api${cleanPath}`; | |
| return `${cleanBase}${apiPrefix}`; | |
| } | |
| // Fallback to relative path using Next.js rewrite | |
| const backendPrefix = cleanPath.startsWith("/backend-api") | |
| ? cleanPath | |
| : `/backend-api${cleanPath.replace(/^\/api/, "")}`; | |
| return backendPrefix; | |
| } | |