Files
test-litestar-addressbook/main.py
Eden Kirin db8fba7207 Settings
2023-09-14 21:03:05 +02:00

42 lines
1.2 KiB
Python

from typing import Any
import uvicorn
from litestar import Litestar
from litestar.contrib.repository.exceptions import (
RepositoryError as RepositoryException,
)
from litestar.openapi import OpenAPIConfig
from app.controllers import create_router
from app.lib import exceptions, settings, sqlalchemy_plugin
from app.lib.service import ServiceError
def create_app(**kwargs: Any) -> Litestar:
kwargs.setdefault("debug", settings.app.DEBUG)
return Litestar(
route_handlers=[create_router()],
openapi_config=OpenAPIConfig(title="My API", version="1.0.0"),
# dependencies={"session": provide_transaction},
plugins=[sqlalchemy_plugin.plugin],
exception_handlers={
RepositoryException: exceptions.repository_exception_to_http_response, # type: ignore[dict-item]
ServiceError: exceptions.service_exception_to_http_response, # type: ignore[dict-item]
},
**kwargs,
)
app = create_app()
if __name__ == "__main__":
uvicorn.run(
app,
host=settings.server.HOST,
log_level=settings.server.LOG_LEVEL,
port=settings.server.PORT,
reload=settings.server.RELOAD,
timeout_keep_alive=settings.server.KEEPALIVE,
)