-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
50 lines (38 loc) · 1.39 KB
/
main.py
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
import os
import uvicorn
from alembic import command
from alembic.config import Config
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from app.initial_setup import create_initial_admin_user
from app.connectors import init_connectors
from app.api import init_routers
from app.app_routes import app_routes
from app.core.config import settings
from app.auth_middleware import auth_middleware
def run_alembic_migrations():
if not os.path.exists("alembic/versions"):
os.makedirs("alembic/versions", exist_ok=True)
alembic_cfg = Config("alembic.ini")
alembic_cfg.set_main_option("sqlalchemy.url", settings.database_url)
command.upgrade(alembic_cfg, "head")
app = FastAPI()
# Create the initial user
@app.on_event("startup")
async def startup_event():
if not os.path.exists("db"):
os.makedirs("db", exist_ok=True)
run_alembic_migrations()
create_initial_admin_user()
# add authentication
app.middleware("http")(auth_middleware)
# Initialize the connectors
init_connectors(app, settings)
# Initialize the routers
init_routers(app)
current_dir = os.path.dirname(os.path.realpath(__file__))
app.mount("/static", StaticFiles(directory=os.path.join(current_dir, "app/static")), name="static")
# Include app_routes
app.include_router(app_routes)
if __name__ == "__main__":
uvicorn.run(app, host=settings.host, port=settings.port, debug=settings.debug)