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/weight-loss-plan") def weight_loss_plan(): plan = { "message": "Welcome to the Weight Loss Plan", "plan": { "week1": { "monday": {"meal": "Salad with grilled chicken", "calories": 300}, "tuesday": {"meal": "Veggie stir-fry with tofu", "calories": 250}, "wednesday": {"meal": "Quinoa salad", "calories": 350}, "thursday": {"meal": "Grilled fish with steamed vegetables", "calories": 400}, "friday": {"meal": "Lentil soup", "calories": 300}, "saturday": {"meal": "Greek yogurt with berries", "calories": 200}, "sunday": {"meal": "Baked sweet potato with cottage cheese", "calories": 350} }, "week2": { "monday": {"meal": "Oatmeal with almond milk", "calories": 300}, "tuesday": {"meal": "Chicken breast with broccoli", "calories": 350}, "wednesday": {"meal": "Chickpea salad", "calories": 300}, "thursday": {"meal": "Turkey burger with lettuce wrap", "calories": 400}, "friday": {"meal": "Vegetable sushi rolls", "calories": 250}, "saturday": {"meal": "Smoothie with spinach and banana", "calories": 200}, "sunday": {"meal": "Egg white omelette with avocado", "calories": 300} } } } return jsonify(plan) if __name__ == "__main__": app.run(debug=True,host="0.0.0.0", port=80)