diff options
author | Ole Mathias Aa. Heggem <olemathias.aa.heggem@gmail.com> | 2025-04-13 07:18:45 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-13 07:18:45 +0200 |
commit | 4ea3a099b05fa910498bfbf1b2d7387118355472 (patch) | |
tree | c248cf6764412471ee3e0d1218761bee19fb396a /api/app/main.py | |
parent | 09710c061d5b8ae86b3dfe49f4b8936c13a10535 (diff) |
Diffstat (limited to 'api/app/main.py')
-rw-r--r-- | api/app/main.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/api/app/main.py b/api/app/main.py new file mode 100644 index 0000000..e7bf524 --- /dev/null +++ b/api/app/main.py @@ -0,0 +1,35 @@ +import time + +from fastapi import FastAPI, Request +from starlette.middleware.cors import CORSMiddleware +from typing import Callable + + +from app.api.main import api_router +from app.core.config import settings + +async def add_process_time_header(request: Request, call_next: Callable): + start_time = time.time() + response = await call_next(request) + process_time = (time.time() - start_time) * 1000 + response.headers["Server-Timing"] = f"Total;dur={process_time: .6f}" + return response + +app = FastAPI( + title=settings.PROJECT_NAME, + openapi_url="/api/openapi.json" +) +app.middleware("http")(add_process_time_header) + +# Set all CORS enabled origins +if settings.all_cors_origins: + app.add_middleware( + CORSMiddleware, + allow_origins=settings.all_cors_origins, + allow_credentials=True, + allow_methods=["*"], + allow_headers=["*"], + expose_headers=["etag"], + ) + +app.include_router(api_router, prefix="/api")
\ No newline at end of file |