# skit_panel_backend/app.py
from flask import Flask
from flask_cors import CORS

# 导入蓝图
from routes.dashboard import dashboard_bp
from routes.system import system_bp
from routes.media import media_bp
from routes.actions import actions_bp
from services.scheduler_service import init_scheduler
def create_app():
    app = Flask(__name__)
    
    # 配置 CORS，允许你的前端地址访问
    # 在开发中， "*" 是最简单的设置
    CORS(app, resources={r"/api/*": {"origins": "*"}})

    # 注册蓝图
    app.register_blueprint(dashboard_bp)
    app.register_blueprint(system_bp)
    app.register_blueprint(media_bp)
    app.register_blueprint(actions_bp)

    @app.route("/")
    def index():
        return "<h1>SkitPanel Backend is running!</h1>"
    with app.app_context():
        init_scheduler()
    return app

if __name__ == '__main__':
    app = create_app()
    # 生产环境应使用 Gunicorn 或 uWSGI
    # debug=True 模式下，修改代码后服务会自动重启
    app.run(host='0.0.0.0', port=5000, debug=True)
