From 6a1d60b1b344e6609068bdc5781b5256cc23763d Mon Sep 17 00:00:00 2001 From: Jun Siang Cheah Date: Sun, 28 Apr 2024 16:03:30 +0100 Subject: [PATCH] feat: warn but not exit if frontend build does not exist --- backend/config.py | 6 +++++- backend/main.py | 15 ++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/backend/config.py b/backend/config.py index f864062d9..f8dbc4d2a 100644 --- a/backend/config.py +++ b/backend/config.py @@ -168,7 +168,11 @@ except: STATIC_DIR = str(Path(os.getenv("STATIC_DIR", "./static")).resolve()) -shutil.copyfile(f"{FRONTEND_BUILD_DIR}/favicon.png", f"{STATIC_DIR}/favicon.png") +frontend_favicon = f"{FRONTEND_BUILD_DIR}/favicon.png" +if os.path.exists(frontend_favicon): + shutil.copyfile(frontend_favicon, f"{STATIC_DIR}/favicon.png") +else: + logging.warning(f"Frontend favicon not found at {frontend_favicon}") #################################### # CUSTOM_NAME diff --git a/backend/main.py b/backend/main.py index 1b2772627..91cce711b 100644 --- a/backend/main.py +++ b/backend/main.py @@ -318,11 +318,16 @@ async def get_manifest_json(): app.mount("/static", StaticFiles(directory=STATIC_DIR), name="static") app.mount("/cache", StaticFiles(directory=CACHE_DIR), name="cache") -app.mount( - "/", - SPAStaticFiles(directory=FRONTEND_BUILD_DIR, html=True), - name="spa-static-files", -) +if os.path.exists(FRONTEND_BUILD_DIR): + app.mount( + "/", + SPAStaticFiles(directory=FRONTEND_BUILD_DIR, html=True), + name="spa-static-files", + ) +else: + log.warning( + f"Frontend build directory not found at '{FRONTEND_BUILD_DIR}'. Serving API only." + ) @app.on_event("shutdown")