Skip to content

Commit 02260ca

Browse files
perf: Determine whether the front end exists
1 parent a048875 commit 02260ca

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

backend/main.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import logging
12
from fastapi.responses import FileResponse
23
from fastapi.staticfiles import StaticFiles
4+
import os
35
import sentry_sdk
46
from fastapi import FastAPI, Path
57
from fastapi.routing import APIRoute
@@ -34,11 +36,21 @@ def custom_generate_unique_id(route: APIRoute) -> str:
3436

3537
app.add_middleware(TokenMiddleware)
3638
app.include_router(api_router, prefix=settings.API_V1_STR)
37-
app.mount("/static", StaticFiles(directory='../frontend/dist'), name="static")
3839

39-
@app.get("/", include_in_schema=False)
40-
async def read_index():
41-
return FileResponse(path="../frontend/dist/index.html")
40+
41+
42+
frontend_dist = os.path.abspath("../frontend/dist")
43+
if not os.path.exists(frontend_dist):
44+
logging.warning(f"The front-end build directory does not exist: {frontend_dist}")
45+
logging.warning("Please make sure you have built the front-end project")
46+
47+
else:
48+
app.mount("/static", StaticFiles(directory=frontend_dist), name="static")
49+
50+
@app.get("/", include_in_schema=False)
51+
async def read_index():
52+
return FileResponse(path=os.path.join(frontend_dist, "index.html"))
53+
4254
if __name__ == "__main__":
4355
import uvicorn
4456
uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True)

0 commit comments

Comments
 (0)