| """ |
| FastAPI entrypoint for the Scouting · Racing Santander Space. |
| """ |
|
|
| import os |
| import warnings |
| from pathlib import Path |
|
|
| |
| |
| warnings.filterwarnings('ignore', category=Warning, module='pandas') |
| warnings.filterwarnings('ignore', message='.*highly fragmented.*') |
|
|
| from fastapi import FastAPI, Request |
| from fastapi.responses import FileResponse, JSONResponse |
| from fastapi.staticfiles import StaticFiles |
|
|
| from auth import AuthMiddleware, register_auth_routes |
| from data import bootstrap_data, get_meta |
| from routes.meta import router as meta_router |
| from routes.rows import router as rows_router |
| from routes.player import router as player_router |
|
|
| APP_DIR = Path(__file__).parent |
| STATIC_DIR = APP_DIR / 'static' |
|
|
| app = FastAPI(title='Scouting · Racing Santander', docs_url='/api/docs', redoc_url=None) |
|
|
| |
| bootstrap_data() |
|
|
| |
| app.add_middleware(AuthMiddleware) |
|
|
| register_auth_routes(app) |
| app.include_router(meta_router, prefix='/api') |
| app.include_router(rows_router, prefix='/api') |
| app.include_router(player_router, prefix='/api') |
|
|
|
|
| @app.get('/healthz') |
| def healthz(): |
| meta = get_meta() |
| return {'ok': True, 'players': meta['n_players'], 'leagues': len(meta['leagues'])} |
|
|
|
|
| |
| app.mount('/static', StaticFiles(directory=STATIC_DIR), name='static') |
|
|
|
|
| @app.get('/') |
| def index(): |
| return FileResponse(STATIC_DIR / 'index.html') |
|
|
|
|
| @app.exception_handler(401) |
| async def unauthorized_handler(request: Request, exc): |
| |
| if request.url.path == '/' or request.url.path.startswith('/static'): |
| return FileResponse(STATIC_DIR / 'index.html') |
| return JSONResponse(status_code=401, content={'detail': 'unauthorized'}) |
|
|