Skip to content

Commit fb29ceb

Browse files
committed
Add robust UI directory mounting with existence checks
- Implement conditional mounting of UI static files - Add logging for missing UI directory - Prevent potential errors from non-existent UI directories
1 parent 3ddc588 commit fb29ceb

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

cloudproxy/main.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,19 @@ async def custom_swagger_ui_html():
7171
async def get_openapi_endpoint():
7272
return custom_openapi()
7373

74-
app.mount("/ui", StaticFiles(directory=(os.path.join(__location__, "../cloudproxy-ui/dist")), html=True), name="static")
75-
app.mount("/css", StaticFiles(directory=(os.path.join(__location__, "../cloudproxy-ui/dist/css")), html=True), name="cssstatic")
76-
app.mount("/js", StaticFiles(directory=(os.path.join(__location__, "../cloudproxy-ui/dist/js"))), name="jsstatic")
74+
# Check if UI directories exist before mounting
75+
ui_dir = os.path.join(__location__, "../cloudproxy-ui/dist")
76+
css_dir = os.path.join(__location__, "../cloudproxy-ui/dist/css")
77+
js_dir = os.path.join(__location__, "../cloudproxy-ui/dist/js")
78+
79+
if os.path.exists(ui_dir):
80+
app.mount("/ui", StaticFiles(directory=ui_dir, html=True), name="static")
81+
if os.path.exists(css_dir):
82+
app.mount("/css", StaticFiles(directory=css_dir, html=True), name="cssstatic")
83+
if os.path.exists(js_dir):
84+
app.mount("/js", StaticFiles(directory=js_dir), name="jsstatic")
85+
else:
86+
logger.warning(f"UI directory {ui_dir} does not exist. UI will not be available.")
7787

7888
origins = ["*"]
7989

0 commit comments

Comments
 (0)