Spaces:
Sleeping
Sleeping
Use start_backend.py in Docker CMD and improve nested route debugging
Browse files- Dockerfile +0 -0
- backend/app/main.py +11 -4
- backend/start_backend.py +4 -3
Dockerfile
CHANGED
|
Binary files a/Dockerfile and b/Dockerfile differ
|
|
|
backend/app/main.py
CHANGED
|
@@ -218,12 +218,19 @@ async def startup_event():
|
|
| 218 |
# DEBUG: print all registered routes for troubleshooting
|
| 219 |
try:
|
| 220 |
robust_print("[ROUTES] Registered FastAPI routes:")
|
| 221 |
-
|
| 222 |
try:
|
| 223 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 224 |
except Exception:
|
| 225 |
-
|
| 226 |
-
|
|
|
|
|
|
|
| 227 |
except Exception:
|
| 228 |
pass
|
| 229 |
robust_print("-" * 50, flush=True)
|
|
|
|
| 218 |
# DEBUG: print all registered routes for troubleshooting
|
| 219 |
try:
|
| 220 |
robust_print("[ROUTES] Registered FastAPI routes:")
|
| 221 |
+
def print_route(route, prefix=""):
|
| 222 |
try:
|
| 223 |
+
if hasattr(route, 'routes') and route.routes:
|
| 224 |
+
for child in route.routes:
|
| 225 |
+
print_route(child, prefix=prefix)
|
| 226 |
+
else:
|
| 227 |
+
methods = ",".join(sorted(list(route.methods))) if hasattr(route, 'methods') and route.methods else ''
|
| 228 |
+
robust_print(f"[ROUTE] path={getattr(route, 'path', str(route))} name={getattr(route, 'name', '')} methods={methods}")
|
| 229 |
except Exception:
|
| 230 |
+
robust_print(f"[ROUTE] path={getattr(route, 'path', str(route))} name={getattr(route, 'name', '')} methods=UNKNOWN")
|
| 231 |
+
|
| 232 |
+
for r in app.routes:
|
| 233 |
+
print_route(r)
|
| 234 |
except Exception:
|
| 235 |
pass
|
| 236 |
robust_print("-" * 50, flush=True)
|
backend/start_backend.py
CHANGED
|
@@ -14,9 +14,10 @@ if "--fast" in sys.argv:
|
|
| 14 |
os.environ["FAKESHIELD_SKIP_WARMUP"] = "1"
|
| 15 |
print(">> Fast Mode enabled: Skipping forensic model pre-loading.")
|
| 16 |
|
| 17 |
-
# Define the command to run (using uvicorn directly for
|
| 18 |
-
#
|
| 19 |
-
|
|
|
|
| 20 |
|
| 21 |
# Change directory to the script's directory (backend)
|
| 22 |
os.chdir(os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
| 14 |
os.environ["FAKESHIELD_SKIP_WARMUP"] = "1"
|
| 15 |
print(">> Fast Mode enabled: Skipping forensic model pre-loading.")
|
| 16 |
|
| 17 |
+
# Define the command to run (using uvicorn directly for stable startup)
|
| 18 |
+
# Use the PORT environment variable if set, otherwise default to Hugging Face's 7860.
|
| 19 |
+
port = int(os.environ.get("PORT", os.environ.get("API_PORT", "7860")))
|
| 20 |
+
cmd = [sys.executable, "-m", "uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", str(port)]
|
| 21 |
|
| 22 |
# Change directory to the script's directory (backend)
|
| 23 |
os.chdir(os.path.dirname(os.path.abspath(__file__)))
|