File size: 1,228 Bytes
15ea62b
9fd370e
da96f77
 
9fd370e
d67439e
15ea62b
8713eac
f1cd69e
15ea62b
4e4ad14
2d8b375
 
 
 
 
4e4ad14
 
 
 
15ea62b
 
 
 
 
 
 
 
 
 
 
a221d93
da96f77
 
 
 
9fd370e
f1cd69e
9fd370e
 
 
 
15ea62b
 
 
4e4ad14
8713eac
4e4ad14
 
 
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 fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import RedirectResponse


from app.api import api_router
from app.core.config import settings
from app.core.errors import error_handler
from app.api.models.ping import PingResponse

from app.utils import print_routes
from app.utils.checks import run_checks

if not run_checks():
    raise Exception("Failed to pass all checks")


app = FastAPI(
    title=settings.PROJECT_NAME, openapi_url=f"{settings.API_V1_STR}/openapi.json"
)

# Set all CORS enabled origins
if settings.BACKEND_CORS_ORIGINS:
    app.add_middleware(
        CORSMiddleware,
        allow_origins=[str(origin) for origin in settings.BACKEND_CORS_ORIGINS],
        allow_credentials=True,
        allow_methods=["*"],
        allow_headers=["*"],
    )


@app.get("/", include_in_schema=False)
async def redirect_to_docs():
    return RedirectResponse(url="/docs")


@app.get("/ping", tags=["ping"], response_model=PingResponse)
async def ping():
    return {"ping": "pong"}


# Include routers
app.include_router(api_router, prefix=settings.API_V1_STR)

# # Error handlers
app.add_exception_handler(500, error_handler)

# Print all routes
print_routes(app)