36 lines
844 B
Python
36 lines
844 B
Python
import os
|
|
import logging
|
|
|
|
from fastapi import FastAPI
|
|
from sqlmodel import SQLModel
|
|
|
|
from xmpp_api.config.config import load_config
|
|
from xmpp_api.db import get_engine
|
|
from xmpp_api.xmpp.component import XmppApiComponent
|
|
import xmpp_api.api.routers.v1 as api_v1
|
|
|
|
|
|
app = FastAPI()
|
|
app.include_router(api_v1.router)
|
|
|
|
|
|
@app.on_event("startup")
|
|
def startup():
|
|
# Setup logging
|
|
logging.basicConfig(
|
|
level=(
|
|
logging.DEBUG
|
|
if os.environ.get("XMPP_API__LOG_LEVEL") == "DEBUG"
|
|
else logging.INFO
|
|
),
|
|
)
|
|
|
|
# TODO: This is kinda ugly
|
|
config = load_config()
|
|
engine = app.dependency_overrides.get(get_engine, get_engine)(config)
|
|
SQLModel.metadata.create_all(engine)
|
|
|
|
# App startup is done. Connect to the XMPP server
|
|
instance = XmppApiComponent.of(config)
|
|
instance.run()
|