1- from pathlib import Path
1+ import uuid
2+
23from fastapi import FastAPI , Request
34from fastapi .middleware .cors import CORSMiddleware
4- from fastapi .responses import HTMLResponse , FileResponse
5+ from fastapi .responses import FileResponse , HTMLResponse
56from fastapi .staticfiles import StaticFiles
67from fastapi .templating import Jinja2Templates
8+ from starlette .middleware .base import BaseHTTPMiddleware
79
810from app .core .config import get_settings
911from app .core .errors import register_exception_handlers
1012from app .core .logging_ import setup_logging
1113from app .routes import plugins as plugins_routes
1214
13- import uuid
14- from starlette .middleware .base import BaseHTTPMiddleware
15-
1615# Initialize settings and logging
1716settings = get_settings ()
1817setup_logging ()
3534 allow_credentials = settings .CORS_ALLOW_CREDENTIALS ,
3635)
3736
37+
3838# Middleware: unique request ID
3939class RequestIDMiddleware (BaseHTTPMiddleware ):
4040 async def dispatch (self , request , call_next ):
@@ -44,26 +44,32 @@ async def dispatch(self, request, call_next):
4444 response .headers ["X-Request-ID" ] = rid
4545 return response
4646
47+
4748app .add_middleware (RequestIDMiddleware )
4849
4950# Register exception handlers
5051register_exception_handlers (app )
5152
53+
5254@app .get ("/" , response_class = HTMLResponse )
5355def index (request : Request ):
5456 return templates .TemplateResponse ("index.html" , {"request" : request , "title" : settings .APP_NAME })
5557
58+
5659@app .get ("/health" )
5760def health ():
5861 return {"status" : "ok" }
5962
63+
6064@app .get ("/env" )
6165def env ():
6266 return settings .summary ()
6367
68+
6469@app .get ("/favicon.ico" , include_in_schema = False )
6570def favicon ():
6671 return FileResponse (str (settings .STATIC_DIR / "favicon.ico" ))
6772
73+
6874# Include plugin routes
6975app .include_router (plugins_routes .router , tags = ["plugins" ])
0 commit comments