34 lines
917 B
Python
34 lines
917 B
Python
from pathlib import Path
|
|
|
|
from flask import Flask, send_from_directory
|
|
|
|
from .config import PROJECT_ROOT
|
|
from .routes.chat import bp as chat_bp
|
|
from .routes.faq import bp as faq_bp
|
|
from .routes.conversation import bp as convo_bp
|
|
|
|
|
|
def create_app():
|
|
dist_dir = PROJECT_ROOT / "frontend" / "dist"
|
|
app = Flask(
|
|
__name__,
|
|
static_folder=str(dist_dir),
|
|
template_folder=str(dist_dir),
|
|
)
|
|
|
|
# 注册路由
|
|
app.register_blueprint(chat_bp)
|
|
app.register_blueprint(faq_bp)
|
|
app.register_blueprint(convo_bp)
|
|
|
|
# 前端静态资源 & SPA 回退
|
|
@app.route("/", defaults={"path": ""})
|
|
@app.route("/<path:path>")
|
|
def serve_frontend(path: str):
|
|
target = dist_dir / (path or "index.html")
|
|
if target.exists():
|
|
return send_from_directory(dist_dir, path or "index.html")
|
|
return send_from_directory(dist_dir, "index.html")
|
|
|
|
return app
|