Spaces:
Runtime error
Runtime error
Greg
Claude Opus 4.7 (1M context)
Preparar despliegue en fly.io: monolito dockerizado + seeder demo
6aa6081 Download backend/app/main.py from Talosware/talos-access: direct link, hf CLI and curl.
- Browser
- Download file 1.88 kB
-
https://huggingface.co/spaces/Talosware/talos-access/resolve/main/backend/app/main.py
- Command line
-
hf download hf://spaces/Talosware/talos-access/backend/app/main.py
-
curl -L -o main.py https://huggingface.co/spaces/Talosware/talos-access/resolve/main/backend/app/main.py
1.88 kB
| import os | |
| from fastapi import FastAPI, Request | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from fastapi.responses import JSONResponse, FileResponse | |
| from fastapi.staticfiles import StaticFiles | |
| from app.core.config import settings | |
| from app.api.v1.router import router | |
| from app.middleware.error_logger import system_error_handler | |
| app = FastAPI( | |
| title=settings.APP_NAME, | |
| debug=settings.DEBUG, | |
| ) | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=settings.cors_origins, | |
| allow_credentials=True, | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| app.include_router(router) | |
| app.add_exception_handler(Exception, system_error_handler) | |
| def health(): | |
| return {"status": "ok", "app": settings.APP_NAME} | |
| # --- Serve the built frontend (monolith). Only active when a build is present, | |
| # so local dev (Vite on a separate port) is unaffected. --- | |
| FRONTEND_DIR = os.path.abspath( | |
| os.getenv("FRONTEND_DIST") | |
| or os.path.join(os.path.dirname(os.path.dirname(__file__)), "static") | |
| ) | |
| if os.path.isdir(FRONTEND_DIR): | |
| _assets_dir = os.path.join(FRONTEND_DIR, "assets") | |
| if os.path.isdir(_assets_dir): | |
| app.mount("/assets", StaticFiles(directory=_assets_dir), name="assets") | |
| _index = os.path.join(FRONTEND_DIR, "index.html") | |
| def spa_fallback(full_path: str): | |
| # API routes and /health are registered earlier and take precedence. | |
| # Serve a real static file if it exists; otherwise return index.html | |
| # so the client-side router can handle the path. | |
| candidate = os.path.normpath(os.path.join(FRONTEND_DIR, full_path)) | |
| within = candidate == FRONTEND_DIR or candidate.startswith(FRONTEND_DIR + os.sep) | |
| if full_path and within and os.path.isfile(candidate): | |
| return FileResponse(candidate) | |
| return FileResponse(_index) | |