Really-amin commited on
Commit
ccf2828
·
verified ·
1 Parent(s): 6deea40

Update app/main.py

Browse files
Files changed (1) hide show
  1. app/main.py +13 -9
app/main.py CHANGED
@@ -4,7 +4,6 @@ import logging
4
  import traceback
5
  from pathlib import Path
6
  from typing import Dict, Any
7
- import asyncio
8
  from datetime import datetime
9
 
10
  from fastapi import FastAPI, File, UploadFile, HTTPException, Request
@@ -151,12 +150,15 @@ app.add_middleware(
151
  allow_headers=["*"],
152
  )
153
 
154
- # Use frontend folder as static files
155
- frontend_dir = Path("frontend")
156
- if not frontend_dir.exists():
157
- logger.warning("⚠️ Frontend directory not found. UI may not load correctly.")
158
- else:
 
159
  app.mount("/static", StaticFiles(directory=frontend_dir), name="static")
 
 
160
 
161
  @app.on_event("startup")
162
  async def startup_event():
@@ -169,11 +171,13 @@ async def startup_event():
169
 
170
  @app.get("/", response_class=HTMLResponse)
171
  async def root():
172
- """Serve main frontend file"""
173
- html_file = Path("frontend/index.html")
174
  if html_file.exists():
175
  return FileResponse(html_file)
176
- return HTMLResponse("<h1>⚠️ Frontend not found</h1><p>Please ensure frontend/index.html exists.</p>")
 
 
 
177
 
178
  @app.get("/health")
179
  async def health_check():
 
4
  import traceback
5
  from pathlib import Path
6
  from typing import Dict, Any
 
7
  from datetime import datetime
8
 
9
  from fastapi import FastAPI, File, UploadFile, HTTPException, Request
 
150
  allow_headers=["*"],
151
  )
152
 
153
+ # Static frontend directory setup
154
+ BASE_DIR = Path(__file__).parent
155
+ frontend_dir = BASE_DIR / "frontend"
156
+
157
+ if frontend_dir.exists():
158
+ logger.info(f"✅ Frontend directory found: {frontend_dir}")
159
  app.mount("/static", StaticFiles(directory=frontend_dir), name="static")
160
+ else:
161
+ logger.warning("⚠️ Frontend directory not found. UI will not load correctly.")
162
 
163
  @app.on_event("startup")
164
  async def startup_event():
 
171
 
172
  @app.get("/", response_class=HTMLResponse)
173
  async def root():
174
+ html_file = frontend_dir / "index.html"
 
175
  if html_file.exists():
176
  return FileResponse(html_file)
177
+ return HTMLResponse("""
178
+ <h1>⚠️ Frontend not found</h1>
179
+ <p>Please ensure 'frontend/index.html' exists in the project root.</p>
180
+ """)
181
 
182
  @app.get("/health")
183
  async def health_check():