Claude commited on
Commit
00b61f3
·
1 Parent(s): 54fdaaa

Fix CSS/static files path resolution in production

Browse files

Use absolute paths (Path(__file__).resolve().parent) for static files
and templates directories instead of relative paths that fail when
the working directory differs in production/Docker environments.

Files changed (1) hide show
  1. app/main.py +8 -3
app/main.py CHANGED
@@ -31,6 +31,9 @@ from sentence_transformers import SentenceTransformer
31
  # Load environment variables
32
  load_dotenv()
33
 
 
 
 
34
  # Initialize FastAPI app
35
  app = FastAPI(
36
  title="SOCAR Historical Documents AI System",
@@ -76,9 +79,11 @@ app.add_middleware(
76
  allow_headers=["Content-Type", "Authorization", "X-Requested-With"],
77
  )
78
 
79
- # Mount static files and templates
80
- app.mount("/static", StaticFiles(directory="app/static"), name="static")
81
- templates = Jinja2Templates(directory="app/templates")
 
 
82
 
83
  # Initialize clients (lazy loading for faster startup)
84
  azure_client = None
 
31
  # Load environment variables
32
  load_dotenv()
33
 
34
+ # Get the directory where main.py is located for absolute path resolution
35
+ BASE_DIR = Path(__file__).resolve().parent
36
+
37
  # Initialize FastAPI app
38
  app = FastAPI(
39
  title="SOCAR Historical Documents AI System",
 
79
  allow_headers=["Content-Type", "Authorization", "X-Requested-With"],
80
  )
81
 
82
+ # Mount static files and templates using absolute paths for production reliability
83
+ STATIC_DIR = BASE_DIR / "static"
84
+ TEMPLATES_DIR = BASE_DIR / "templates"
85
+ app.mount("/static", StaticFiles(directory=str(STATIC_DIR)), name="static")
86
+ templates = Jinja2Templates(directory=str(TEMPLATES_DIR))
87
 
88
  # Initialize clients (lazy loading for faster startup)
89
  azure_client = None