Get FastAPI application.
This is the main constructor of an application.
Returns:
Source code in hestia/web/application.py
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79 | def get_app() -> HestiaApp:
"""
Get FastAPI application.
This is the main constructor of an application.
:return: application.
"""
configure_logging()
if settings.sentry_dsn:
# Enables sentry integration.
sentry_sdk.init(
dsn=settings.sentry_dsn,
traces_sample_rate=settings.sentry_sample_rate,
environment=settings.environment,
integrations=[
FastApiIntegration(transaction_style="endpoint"),
LoggingIntegration(
level=logging.getLevelName(
settings.log_level.value,
),
event_level=logging.ERROR,
),
SqlalchemyIntegration(),
],
)
app = HestiaApp(
title="hestia",
version=metadata.version("hestia"),
docs_url=None,
redoc_url=None,
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")
# Adds static directory.
# This directory is used to access swagger files.
app.mount(
"/static",
StaticFiles(directory=APP_ROOT / "static"),
name="static",
)
# init. extensions
_init_extensions(app)
return app
|