forked from iti-framework/iTi-Flask
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
747 B
Python
22 lines
747 B
Python
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('/<path:fallback>')
|
|
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) |