feat: Implement static login page and fix server errors. Attempt 2
This commit is contained in:
@@ -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.
|
For the project we are using Discord 💬 and Nextcloud ☁️ for communications.
|
||||||
* ☁️ [Nextcloud](https://cloud9.ramforth.net/)
|
* ☁️ [Nextcloud](https://cloud9.ramforth.net/)
|
||||||
* 💬 [Discord](https://discord.gg/Zaxp6ch9hs)
|
* 💬 [Discord](https://discord.gg/Zaxp6ch9hs)
|
||||||
|
* 🌐 [Public website](https://multichat.ramforth.net/)
|
||||||
|
|
||||||
|
##
|
||||||
|
|
||||||
👨💻 - Coded on and for Linux - 2025
|
👨💻 - Coded on and for Linux - 2025
|
||||||
12
main.py
12
main.py
@@ -1,3 +1,4 @@
|
|||||||
|
import os
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
from starlette.middleware.sessions import SessionMiddleware
|
from starlette.middleware.sessions import SessionMiddleware
|
||||||
from starlette.staticfiles import StaticFiles
|
from starlette.staticfiles import StaticFiles
|
||||||
@@ -8,6 +9,11 @@ from database import engine
|
|||||||
import auth # Import the new auth module
|
import auth # Import the new auth module
|
||||||
from config import settings # Import settings to get the secret key
|
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
|
# 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
|
# we defined. It will create the `multichat_overlay.db` file with the
|
||||||
# 'users' and 'settings' tables if they don't exist.
|
# 'users' and 'settings' tables if they don't exist.
|
||||||
@@ -15,8 +21,8 @@ models.Base.metadata.create_all(bind=engine)
|
|||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
# Mount the 'static' directory to serve files like login.html
|
# Mount the 'static' directory using an absolute path for reliability
|
||||||
app.mount("/static", StaticFiles(directory="static"), name="static")
|
app.mount("/static", StaticFiles(directory=STATIC_DIR), name="static")
|
||||||
|
|
||||||
# Add the authentication router
|
# Add the authentication router
|
||||||
app.include_router(auth.router)
|
app.include_router(auth.router)
|
||||||
@@ -27,4 +33,4 @@ app.add_middleware(SessionMiddleware, secret_key=settings.ENCRYPTION_KEY)
|
|||||||
|
|
||||||
@app.get("/")
|
@app.get("/")
|
||||||
async def read_root():
|
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