| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- from flask import Flask, jsonify
- from flask_cors import CORS # 导入Flask-CORS
- from api.routes import register_routes
- def create_app():
- app = Flask(__name__)
-
- # 配置CORS - 核心修改部分
- CORS(app,
- origins=[
- 'http://localhost:9527',
- 'https://adminpre.bjzxtw.org.cn',
- 'http://adminpre.bjzxtw.org.cn',
- 'https://admin.bjzxtw.org.cn',
- 'http://admin.bjzxtw.org.cn'
- ], # 明确允许你的前端域名
- supports_credentials=True, # 允许携带Cookie等凭证
- methods=['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'], # 允许的HTTP方法
- #allow_headers=['Content-Type', 'Authorization','userurl'], # 允许的请求头
- allow_headers='*', # 允许的请求头
- expose_headers=None, # 允许浏览器访问的响应头
- max_age=600) # 预检请求缓存时间(秒)
-
- # 路由检查
- @app.route('/health')
- def health():
- return jsonify({'status': 'healthy', 'service': 'aiserv'})
-
- # 添加根路由
- @app.route('/')
- def index():
- return jsonify({
- 'service': 'AIServ',
- 'version': '1.2',
- 'status': 'running'
- })
-
- # 注册其他路由
- register_routes(app)
- return app
- if __name__ == '__main__':
- app = create_app()
- print("🚀 小龙包服务启动...")
- print("📡 监听地址: 0.0.0.0:5000")
- print("🌐 外部访问: http://localhost:5000")
- print("🔓 CORS已启用,允许跨域访问")
- print(f"✅ 允许的源: https://apipre1.bjzxtw.org.cn")
-
- app.run(
- host='0.0.0.0',
- port=5000,
- debug=False,
- threaded=True
- )
|