Archived
Add startup initialization
This commit is contained in:
+23
-4
@@ -1,15 +1,33 @@
|
||||
from contextlib import asynccontextmanager
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from routes import admin, auth, review, stats
|
||||
import duckdb
|
||||
|
||||
app = FastAPI()
|
||||
from settings import settings
|
||||
from lib.logger import logger
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
from lib import startup
|
||||
|
||||
startup.init_app()
|
||||
global db
|
||||
db = duckdb.connect(str(settings.database_file))
|
||||
yield
|
||||
db.close()
|
||||
|
||||
|
||||
logger.info("Starting app")
|
||||
app = FastAPI(lifespan=lifespan)
|
||||
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=['*'],
|
||||
allow_origins=["*"],
|
||||
allow_credentials=True,
|
||||
allow_methods=['*'],
|
||||
allow_headers=['*'],
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
app.include_router(auth.router)
|
||||
@@ -17,6 +35,7 @@ app.include_router(admin.router)
|
||||
app.include_router(review.router)
|
||||
app.include_router(stats.router)
|
||||
|
||||
|
||||
@app.get("/")
|
||||
def read_root():
|
||||
return {"Hello": "World"}
|
||||
Reference in New Issue
Block a user