Z User commited on
Commit
11dc522
·
1 Parent(s): 88cdea1

fix: serve WebUI static files directly, proxy /assets/* to client dir

Browse files

- /webui serves index.html from webui-client
- /assets/*, /favicon* served from webui-client directly
- /api/* still proxied to BFF on :6060
- Avoid BFF / route issue by serving static files locally

Files changed (1) hide show
  1. entry.py +42 -25
entry.py CHANGED
@@ -390,31 +390,48 @@ class ProxyHandler(BaseHTTPRequestHandler):
390
  if path == "/api/logs/stream":
391
  return self._handle_sse()
392
 
393
- # ── WebUI BFF routes: /webui, /webui/*, /api/*, /v1/*, /assets/*,
394
- # /favicon*, /health, /upload, /webhook → all proxy to BFF ──
395
- # The BFF handles SPA fallback for unknown paths.
396
- is_webui_path = (
397
- path.startswith("/webui") or
398
- path.startswith("/api/") or
399
- path.startswith("/v1/") or
400
- path.startswith("/assets/") or
401
- path.startswith("/favicon") or
402
- path == "/health" or
403
- path == "/upload" or
404
- path == "/webhook" or
405
- path.startswith("/socket.io/")
406
- )
407
- if is_webui_path:
408
- # Rewrite /webui/* to /* for BFF (it serves from its own static dir)
409
- if path.startswith("/webui") and len(path) > 5:
410
- bff_path = path[5:] # /webui/assets/foo → /assets/foo
411
- if not bff_path:
412
- bff_path = "/"
413
- elif path == "/webui":
414
- bff_path = "/"
415
- else:
416
- bff_path = self.path
417
- return self._forward_to_webui(bff_path + ("?" + qs if qs else ""), "GET")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
418
 
419
  self.send_error(404)
420
 
 
390
  if path == "/api/logs/stream":
391
  return self._handle_sse()
392
 
393
+ # ── WebUI SPA: /webui, /webui/* serve from webui-client static dir ──
394
+ if path.startswith("/webui"):
395
+ # Map /webui /, /webui/xxx → /xxx for the static dir
396
+ if path in ("/webui", "/webui/"):
397
+ index_path = os.path.join(WEBUI_CLIENT_DIR, "index.html")
398
+ if os.path.isfile(index_path):
399
+ return self._send_html(index_path)
400
+ # Try static file
401
+ static_path = os.path.join(WEBUI_CLIENT_DIR, path[len("/webui"):].lstrip("/"))
402
+ if os.path.isfile(static_path):
403
+ return self._send_file(static_path)
404
+ # SPA fallback
405
+ index_path = os.path.join(WEBUI_CLIENT_DIR, "index.html")
406
+ if os.path.isfile(index_path):
407
+ return self._send_html(index_path)
408
+ # Final fallback: proxy to BFF
409
+ return self._forward_to_webui(path[5:] or "/", "GET")
410
+
411
+ # ── WebUI static assets (referenced by SPA as /assets/*, /favicon*) ──
412
+ # These must be served from webui-client dir because the SPA uses absolute paths
413
+ if path.startswith("/assets/") or path.startswith("/favicon") or path == "/logo.png":
414
+ static_path = os.path.join(WEBUI_CLIENT_DIR, path.lstrip("/"))
415
+ if os.path.isfile(static_path):
416
+ return self._send_file(static_path)
417
+ # If not found locally, try proxying to BFF
418
+ return self._forward_to_webui(self.path, "GET")
419
+
420
+ # ── WebUI API routes: /api/*, /v1/* → proxy to WebUI BFF ──
421
+ if path.startswith("/api/") or path.startswith("/v1/"):
422
+ return self._forward_to_webui(self.path, "GET")
423
+
424
+ # ── /health → proxy to BFF ──
425
+ if path == "/health":
426
+ return self._forward_to_webui("/health", "GET")
427
+
428
+ # ── /upload, /webhook → proxy to BFF ──
429
+ if path in ("/upload", "/webhook"):
430
+ return self._forward_to_webui(self.path, "GET")
431
+
432
+ # ── /socket.io/* → proxy to BFF (WebSocket upgrade handled separately) ──
433
+ if path.startswith("/socket.io/"):
434
+ return self._forward_to_webui(self.path, "GET")
435
 
436
  self.send_error(404)
437