chore: sync local changes (2026-03-12)

This commit is contained in:
2026-03-12 18:58:36 +08:00
parent 2bd4f06188
commit d8c1e1ee6c
49 changed files with 409 additions and 182 deletions

View File

@@ -42,6 +42,7 @@ PROJECT_ROOT = BACKEND_ROOT.parent # Root project directory
FRONTEND_ROOT = PROJECT_ROOT / "mengyadriftbottle-frontend" # Frontend directory
TEMPLATES_DIR = FRONTEND_ROOT / "templates" # Templates in frontend
STATIC_DIR = FRONTEND_ROOT / "static" # Static files in frontend
BACKGROUND_DIR = BACKEND_ROOT / "background" # Background images directory
FRONTEND_DIST = Path(
os.environ.get("DRIFT_BOTTLE_FRONTEND_DIST") or PROJECT_ROOT / "frontend-dist"
)
@@ -547,7 +548,20 @@ def admin_settings():
# ---------------------------------------------------------------------- #
# ==============================后端公开API============================== #
# ==============================静态文件服务============================== #
# ---------------------------------------------------------------------- #
@app.route("/background/<path:filename>")
def serve_background_image(filename: str):
"""Serve background images from the background directory."""
if not BACKGROUND_DIR.exists():
abort(404)
return send_from_directory(str(BACKGROUND_DIR), filename)
# ---------------------------------------------------------------------- #
# ==============================前端应用服务============================== #
# ---------------------------------------------------------------------- #
@@ -558,6 +572,10 @@ def serve_frontend_app(path: str):
if path.startswith("api/"):
abort(404)
# 如果路径是 background/,由上面的路由处理
if path.startswith("background/"):
abort(404)
if not FRONTEND_DIST.exists():
return ("Frontend build not found. Please run npm run build first.", 404)
@@ -569,4 +587,6 @@ def serve_frontend_app(path: str):
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5002, debug=True)
port = int(os.environ.get("PORT", 5002))
debug = os.environ.get("FLASK_DEBUG", "False").lower() == "true"
app.run(host="0.0.0.0", port=port, debug=debug)