from flask import Flask, jsonify, send_from_directory app = Flask(__name__, static_folder="public", static_url_path="") # 根路径返回 index.html @app.route("/") def serve_index(): return send_from_directory(app.static_folder, "index.html") # API 子路径,提供每日菜谱数据 @app.route("/api/menu") def api_menu(): # 模拟每日菜谱数据 menu = { "message": "Today's Menu", "data": [ {"name": "番茄炒蛋", "ingredients": ["番茄", "鸡蛋", "盐", "糖"]}, {"name": "清炒时蔬", "ingredients": ["西兰花", "胡萝卜", "蒜末"]}, {"name": "红烧肉", "ingredients": ["五花肉", "酱油", "糖", "料酒"]} ] } return jsonify(menu) if __name__ == "__main__": app.run(debug=True, port=80)