-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
51 lines (37 loc) · 1.4 KB
/
Copy pathmain.py
File metadata and controls
51 lines (37 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from pathlib import Path
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import FileResponse
from loguru import logger
from app.api.routes import router as license_router
from app.core.config import settings
from app.core.logging import configure_logging
FRONTEND_INDEX = Path(__file__).parent / "frontend" / "index.html"
def create_app() -> FastAPI:
configure_logging(settings)
app = FastAPI(
title=settings.app_name,
description="API production-ready para consulta de cartas de conducao via scraping assincrono.",
version="1.0.0",
debug=settings.app_debug,
docs_url="/docs",
redoc_url="/redoc",
openapi_url="/openapi.json",
)
app.add_middleware(
CORSMiddleware,
allow_origins=settings.allowed_origins_list,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
app.include_router(license_router, prefix=settings.api_prefix)
@app.get("/health", tags=["Saude"], summary="Health check")
async def health_check() -> dict[str, str]:
return {"status": "ok"}
@app.get("/", tags=["Frontend"], summary="Interface web")
async def frontend() -> FileResponse:
return FileResponse(FRONTEND_INDEX)
logger.info("{} started in {} mode", settings.app_name, settings.app_env)
return app
app = create_app()