fix(dashboard): use absolute path for bundled dist and handle 404s gracefully
This commit is contained in:
@@ -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():
|
||||
|
||||
Reference in New Issue
Block a user