1+ import logging
12from fastapi .responses import FileResponse
23from fastapi .staticfiles import StaticFiles
4+ import os
35import sentry_sdk
46from fastapi import FastAPI , Path
57from fastapi .routing import APIRoute
@@ -34,11 +36,21 @@ def custom_generate_unique_id(route: APIRoute) -> str:
3436
3537app .add_middleware (TokenMiddleware )
3638app .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+
4254if __name__ == "__main__" :
4355 import uvicorn
4456 uvicorn .run ("main:app" , host = "0.0.0.0" , port = 8000 , reload = True )
0 commit comments