From 0b534f65c2e426c9de1dfc296af65857effba462 Mon Sep 17 00:00:00 2001 From: LIghtJUNction Date: Sun, 15 Mar 2026 18:05:15 +0800 Subject: [PATCH] fix(dashboard): use absolute path for bundled dist and handle 404s gracefully --- astrbot/dashboard/server.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/astrbot/dashboard/server.py b/astrbot/dashboard/server.py index 8c5734182..08ff7c483 100644 --- a/astrbot/dashboard/server.py +++ b/astrbot/dashboard/server.py @@ -12,6 +12,7 @@ from typing import Protocol import jwt import psutil +import werkzeug.exceptions from flask.json.provider import DefaultJSONProvider from hypercorn.asyncio import serve from hypercorn.config import Config as HyperConfig @@ -106,7 +107,7 @@ class AstrBotDashboard: if os.path.exists(user_dist): self.data_path = os.path.abspath(user_dist) elif _BUNDLED_DIST.exists(): - self.data_path = str(_BUNDLED_DIST) + self.data_path = str(_BUNDLED_DIST.absolute()) logger.info("Using bundled dashboard dist: %s", self.data_path) else: self.data_path = os.path.abspath(user_dist) @@ -143,7 +144,11 @@ class AstrBotDashboard: async def index(): if not self.enable_webui: return "WebUI is disabled." - return await self.app.send_static_file("index.html") + try: + return await self.app.send_static_file("index.html") + except werkzeug.exceptions.NotFound: + logger.error(f"Dashboard index.html not found in {self.data_path}") + return "Dashboard files not found.", 404 @self.app.errorhandler(404) async def not_found(e): @@ -151,7 +156,10 @@ class AstrBotDashboard: return "WebUI is disabled." if request.path.startswith("/api/"): return jsonify(Response().error("Not Found").to_json()), 404 - return await self.app.send_static_file("index.html") + try: + return await self.app.send_static_file("index.html") + except werkzeug.exceptions.NotFound: + return "Dashboard files not found.", 404 @self.app.before_serving async def startup():