feat: Implement static login page and fix server errors. Attempt 2
This commit is contained in:
12
main.py
12
main.py
@@ -1,3 +1,4 @@
|
||||
import os
|
||||
from fastapi import FastAPI
|
||||
from starlette.middleware.sessions import SessionMiddleware
|
||||
from starlette.staticfiles import StaticFiles
|
||||
@@ -8,6 +9,11 @@ from database import engine
|
||||
import auth # Import the new auth module
|
||||
from config import settings # Import settings to get the secret key
|
||||
|
||||
# --- Absolute Path Configuration ---
|
||||
# Get the absolute path of the directory where this file is located
|
||||
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.
|
||||
@@ -15,8 +21,8 @@ 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")
|
||||
# Mount the 'static' directory using an absolute path for reliability
|
||||
app.mount("/static", StaticFiles(directory=STATIC_DIR), name="static")
|
||||
|
||||
# Add the authentication router
|
||||
app.include_router(auth.router)
|
||||
@@ -27,4 +33,4 @@ app.add_middleware(SessionMiddleware, secret_key=settings.ENCRYPTION_KEY)
|
||||
|
||||
@app.get("/")
|
||||
async def read_root():
|
||||
return FileResponse("static/login.html")
|
||||
return FileResponse(os.path.join(STATIC_DIR, "login.html"))
|
||||
Reference in New Issue
Block a user