Spaces:
Running
Running
fix: use same-origin API calls in production + HEAD method support for Next.js prefetch
Browse files- backend/app/main.py +6 -1
- frontend/src/lib/api.ts +1 -1
backend/app/main.py
CHANGED
|
@@ -101,7 +101,7 @@ if os.path.exists(FRONTEND_BUILD_DIR):
|
|
| 101 |
if os.path.exists(static_dir):
|
| 102 |
app.mount("/static", StaticFiles(directory=static_dir), name="static")
|
| 103 |
|
| 104 |
-
@app.
|
| 105 |
async def serve_frontend(full_path: str):
|
| 106 |
"""Serve Next.js static export — tries exact file, then .html, then index.html."""
|
| 107 |
# Try exact file path
|
|
@@ -114,6 +114,11 @@ if os.path.exists(FRONTEND_BUILD_DIR):
|
|
| 114 |
if os.path.isfile(html_path):
|
| 115 |
return FileResponse(html_path)
|
| 116 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
# Try as directory index
|
| 118 |
index_path = os.path.join(FRONTEND_BUILD_DIR, full_path, "index.html")
|
| 119 |
if os.path.isfile(index_path):
|
|
|
|
| 101 |
if os.path.exists(static_dir):
|
| 102 |
app.mount("/static", StaticFiles(directory=static_dir), name="static")
|
| 103 |
|
| 104 |
+
@app.api_route("/{full_path:path}", methods=["GET", "HEAD"])
|
| 105 |
async def serve_frontend(full_path: str):
|
| 106 |
"""Serve Next.js static export — tries exact file, then .html, then index.html."""
|
| 107 |
# Try exact file path
|
|
|
|
| 114 |
if os.path.isfile(html_path):
|
| 115 |
return FileResponse(html_path)
|
| 116 |
|
| 117 |
+
# Try .txt for RSC payloads (Next.js uses .txt for RSC data)
|
| 118 |
+
txt_path = os.path.join(FRONTEND_BUILD_DIR, f"{full_path}.txt")
|
| 119 |
+
if os.path.isfile(txt_path):
|
| 120 |
+
return FileResponse(txt_path)
|
| 121 |
+
|
| 122 |
# Try as directory index
|
| 123 |
index_path = os.path.join(FRONTEND_BUILD_DIR, full_path, "index.html")
|
| 124 |
if os.path.isfile(index_path):
|
frontend/src/lib/api.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
| 3 |
* Handles authentication headers and base URL configuration.
|
| 4 |
*/
|
| 5 |
|
| 6 |
-
const API_BASE = process.env.NEXT_PUBLIC_API_URL || "
|
| 7 |
|
| 8 |
interface FetchOptions extends RequestInit {
|
| 9 |
token?: string;
|
|
|
|
| 3 |
* Handles authentication headers and base URL configuration.
|
| 4 |
*/
|
| 5 |
|
| 6 |
+
const API_BASE = process.env.NEXT_PUBLIC_API_URL || "";
|
| 7 |
|
| 8 |
interface FetchOptions extends RequestInit {
|
| 9 |
token?: string;
|