Create the FastAPI application
See https://fastapi.tiangolo.com/tutorial/first-steps/ to learn how to
customize your FastAPI application
Source code in template_api/application.py
| def declare_application() -> FastAPI:
"""Create the FastAPI application
See https://fastapi.tiangolo.com/tutorial/first-steps/ to learn how to
customize your FastAPI application
"""
app = FastAPI(
title=f"REST API form {settings.app_name}",
description=f"Use {settings.app_name} thanks to FastAPI",
lifespan=lifespan
)
# Add PrometheusMiddleware
app.add_middleware(PrometheusMiddleware)
app.add_route("/metrics", metrics)
# CORS middleware that allows all origins to avoid CORS problems
# see https://fastapi.tiangolo.com/tutorial/cors/#use-corsmiddleware
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
#
app.include_router(main_routeur, prefix=settings.api_entrypoint)
return app
|