from apiflask import APIBlueprint from flask import send_from_directory, current_app import os bp = APIBlueprint("front", __name__, tag="前端") def _get_frontend_path(): return os.path.join(current_app.static_folder, current_app.config.get("FRONTEND_PATH", "")) @bp.get("/") def index(): """渲染前端 SPA 入口页面""" return send_from_directory(_get_frontend_path(), "index.html") @bp.get('/') def fallback(fallback): """兜底: 避免history模式下的影响""" frontend_path = _get_frontend_path() if not os.path.exists(os.path.join(frontend_path, fallback)): return send_from_directory(frontend_path, 'index.html') else: return send_from_directory(frontend_path, fallback)