Update: Logic with Twitch login now works.
This commit is contained in:
15
main.py
15
main.py
@@ -3,6 +3,7 @@ from fastapi import FastAPI, Request
|
||||
from starlette.middleware.sessions import SessionMiddleware
|
||||
from starlette.staticfiles import StaticFiles
|
||||
from starlette.responses import FileResponse, RedirectResponse
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
import models
|
||||
from database import engine
|
||||
@@ -14,12 +15,16 @@ from config import settings # Import settings to get the secret key
|
||||
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
STATIC_DIR = os.path.join(BASE_DIR, "static")
|
||||
|
||||
# This line tells SQLAlchemy to create all the tables based on the models
|
||||
# we defined. It will create the `multichat_overlay.db` file with the
|
||||
# 'users' and 'settings' tables if they don't exist.
|
||||
models.Base.metadata.create_all(bind=engine)
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
# This code runs on startup
|
||||
print("Application startup: Creating database tables...")
|
||||
models.Base.metadata.create_all(bind=engine)
|
||||
print("Application startup: Database tables created.")
|
||||
yield
|
||||
# Code below yield runs on shutdown, if needed
|
||||
|
||||
app = FastAPI()
|
||||
app = FastAPI(lifespan=lifespan)
|
||||
|
||||
# Mount the 'static' directory using an absolute path for reliability
|
||||
app.mount("/static", StaticFiles(directory=STATIC_DIR), name="static")
|
||||
|
||||
Reference in New Issue
Block a user