Mounting static directory
This commit is contained in:
12
main.py
12
main.py
@@ -1,6 +1,7 @@
|
||||
# main.py
|
||||
import logging
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
|
||||
from fastapi import Depends, FastAPI, HTTPException
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
@@ -20,6 +21,10 @@ from middleware.vendor_context import vendor_context_middleware
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# Get the project root directory (where main.py is located)
|
||||
BASE_DIR = Path(__file__).resolve().parent
|
||||
STATIC_DIR = BASE_DIR / "static"
|
||||
|
||||
# FastAPI app with lifespan
|
||||
app = FastAPI(
|
||||
title=settings.project_name,
|
||||
@@ -44,9 +49,12 @@ app.add_middleware(
|
||||
app.middleware("http")(vendor_context_middleware)
|
||||
|
||||
# ========================================
|
||||
# MOUNT STATIC FILES - ADD THIS SECTION
|
||||
# MOUNT STATIC FILES - Use absolute path
|
||||
# ========================================
|
||||
app.mount("/static", StaticFiles(directory="static"), name="static")
|
||||
if STATIC_DIR.exists():
|
||||
app.mount("/static", StaticFiles(directory=str(STATIC_DIR)), name="static")
|
||||
else:
|
||||
logger.warning(f"Static directory not found at {STATIC_DIR}")
|
||||
# ========================================
|
||||
|
||||
# Include API router
|
||||
|
||||
Reference in New Issue
Block a user