-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.py
More file actions
85 lines (69 loc) · 2.21 KB
/
Copy pathapp.py
File metadata and controls
85 lines (69 loc) · 2.21 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
"""ASGI application factory."""
from __future__ import annotations
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from litestar import Litestar
__all__ = ["create_app"]
def create_app() -> Litestar:
"""Application factory to instantiate a Litestar application.
Returns:
Litestar: The Litestar application.
"""
from advanced_alchemy.exceptions import (
RepositoryError as AdvancedAlchemyRepositoryError,
)
from litestar import Litestar
from pydantic import SecretStr
from byte_api import domain
from byte_api.lib import (
cors,
db,
exceptions,
log,
openapi,
schema,
settings,
static_files,
template,
)
from byte_api.lib.dependencies import create_collection_dependencies
dependencies = create_collection_dependencies()
from byte_api.domain.web.controllers.websocket import set_startup_time
return Litestar(
# Handlers
exception_handlers={
exceptions.ApplicationError: exceptions.exception_to_http_response,
AdvancedAlchemyRepositoryError: exceptions.exception_to_http_response,
},
route_handlers=[*domain.routes],
# Configs
cors_config=cors.config,
logging_config=log.config,
openapi_config=openapi.config,
static_files_config=static_files.config,
template_config=template.config,
dependencies=dependencies,
# Lifecycle
before_send=[log.controller.BeforeSendHandler()],
on_shutdown=[],
on_startup=[
lambda: log.configure(log.default_processors), # type: ignore[arg-type]
set_startup_time,
],
on_app_init=[],
# Other
debug=settings.project.DEBUG,
middleware=[log.controller.middleware_factory],
signature_namespace=domain.signature_namespace,
type_encoders={
SecretStr: str,
schema.CamelizedBaseModel: schema.serialize_camelized_model,
},
plugins=[db.plugin],
)
def create_bot() -> None:
"""Application factory to instantiate a Discord bot.
.. todo:: Move into this file.
"""
app = create_app()
bot = create_bot()