backend/med_backend/web/application.py

44 lines
1.1 KiB
Python
Raw Normal View History

2022-12-07 20:16:44 +03:00
from importlib import metadata
from fastapi import FastAPI
from fastapi.responses import UJSONResponse
2022-12-09 16:40:14 +03:00
from starlette.middleware.cors import CORSMiddleware
2022-12-07 20:16:44 +03:00
from med_backend.web.api.router import api_router
from med_backend.web.lifetime import register_shutdown_event, register_startup_event
def get_app() -> FastAPI:
"""
Get FastAPI application.
This is the main constructor of an application.
:return: application.
"""
app = FastAPI(
title="med_backend",
description="",
version=metadata.version("med_backend"),
docs_url="/api/docs",
redoc_url="/api/redoc",
openapi_url="/api/openapi.json",
default_response_class=UJSONResponse,
)
# Adds startup and shutdown events.
register_startup_event(app)
register_shutdown_event(app)
# Main router for the API.
app.include_router(router=api_router, prefix="/api")
2022-12-09 16:40:14 +03:00
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
2022-12-07 20:16:44 +03:00
return app