Spaces:
Running
Running
fix(build): dynamically resolve frontend build path in main.py
Browse filesResolves the production path issue where FRONTEND_BUILD_DIR was incorrectly resolved to /frontend/out inside the Docker container since the backend code was relocated to /app/app. Now dynamically falls back to /app/frontend/out in container environments.
- backend/app/main.py +9 -1
backend/app/main.py
CHANGED
|
@@ -216,7 +216,15 @@ def db_health():
|
|
| 216 |
}
|
| 217 |
|
| 218 |
# ββ Serve Next.js Frontend (production) ββββββββββββββ
|
| 219 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 220 |
|
| 221 |
if os.path.exists(FRONTEND_BUILD_DIR):
|
| 222 |
# Serve static assets (JS, CSS, images)
|
|
|
|
| 216 |
}
|
| 217 |
|
| 218 |
# ββ Serve Next.js Frontend (production) ββββββββββββββ
|
| 219 |
+
# In local development, frontend build is at ../../frontend/out relative to backend/app/main.py
|
| 220 |
+
# In Docker container (where app is copied to /app/app), frontend build is at /app/frontend/out (which is ../frontend/out relative to /app/app/main.py)
|
| 221 |
+
_local_build_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "frontend", "out"))
|
| 222 |
+
_docker_build_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "frontend", "out"))
|
| 223 |
+
|
| 224 |
+
if os.path.exists(_docker_build_dir):
|
| 225 |
+
FRONTEND_BUILD_DIR = _docker_build_dir
|
| 226 |
+
else:
|
| 227 |
+
FRONTEND_BUILD_DIR = _local_build_dir
|
| 228 |
|
| 229 |
if os.path.exists(FRONTEND_BUILD_DIR):
|
| 230 |
# Serve static assets (JS, CSS, images)
|