Spaces:
Sleeping
Sleeping
File size: 1,545 Bytes
868b252 |
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 52 53 54 55 56 |
from importlib import metadata
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import UJSONResponse
from reworkd_platform.logging import configure_logging
from reworkd_platform.settings import settings
from reworkd_platform.web.api.error_handling import platformatic_exception_handler
from reworkd_platform.web.api.errors import PlatformaticError
from reworkd_platform.web.api.router import api_router
from reworkd_platform.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.
"""
configure_logging()
app = FastAPI(
title="Reworkd Platform API",
version=metadata.version("reworkd_platform"),
docs_url="/api/docs",
redoc_url="/api/redoc",
openapi_url="/api/openapi.json",
default_response_class=UJSONResponse,
)
app.add_middleware(
CORSMiddleware,
allow_origins=[settings.frontend_url],
allow_origin_regex=settings.allowed_origins_regex,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# 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.exception_handler(PlatformaticError)(platformatic_exception_handler)
return app
|