31 lines
1.2 KiB
Python
31 lines
1.2 KiB
Python
from fastapi import FastAPI
|
|
from starlette.middleware.sessions import SessionMiddleware
|
|
from starlette.staticfiles import StaticFiles
|
|
from starlette.responses import HTMLResponse
|
|
|
|
import models
|
|
from database import engine
|
|
import auth # Import the new auth module
|
|
from config import settings # Import settings to get the secret key
|
|
|
|
# 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)
|
|
|
|
app = FastAPI()
|
|
|
|
# Mount the 'static' directory to serve files like login.html
|
|
app.mount("/static", StaticFiles(directory="static"), name="static")
|
|
|
|
# Add the authentication router
|
|
app.include_router(auth.router)
|
|
|
|
# Add session middleware. A secret key is required for signing the session cookie.
|
|
# We can reuse our encryption key for this, but in production you might want a separate key.
|
|
app.add_middleware(SessionMiddleware, secret_key=settings.ENCRYPTION_KEY)
|
|
|
|
@app.get("/")
|
|
async def read_root() -> HTMLResponse:
|
|
with open("static/login.html") as f:
|
|
return HTMLResponse(content=f.read(), status_code=200) |