backend/med_backend/web/application.py
2022-12-09 16:40:14 +03:00

44 lines
1.1 KiB
Python

from importlib import metadata
from fastapi import FastAPI
from fastapi.responses import UJSONResponse
from starlette.middleware.cors import CORSMiddleware
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")
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
return app