From 603eb84d3414b2ea60eb3dc3e569101bce12917d Mon Sep 17 00:00:00 2001 From: ramforth Date: Mon, 17 Nov 2025 00:54:13 +0100 Subject: [PATCH] feat: Implement static login page and fix server errors. Attempt 2 --- README.md | 3 +++ main.py | 12 +++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3676849..faa2b70 100644 --- a/README.md +++ b/README.md @@ -32,5 +32,8 @@ This project follows a professional development workflow. Gitea is our single so For the project we are using Discord 💬 and Nextcloud ☁️ for communications. * ☁️ [Nextcloud](https://cloud9.ramforth.net/) * 💬 [Discord](https://discord.gg/Zaxp6ch9hs) + * 🌐 [Public website](https://multichat.ramforth.net/) + +## 👨‍💻 - Coded on and for Linux - 2025 \ No newline at end of file diff --git a/main.py b/main.py index 26fbaec..aed260b 100644 --- a/main.py +++ b/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") \ No newline at end of file + return FileResponse(os.path.join(STATIC_DIR, "login.html")) \ No newline at end of file