update pay function
This commit is contained in:
49
integrate_mcp_to_app.py
Normal file
49
integrate_mcp_to_app.py
Normal file
@@ -0,0 +1,49 @@
|
||||
# integrate_mcp_to_app.py - 集成 MCP 到主应用的示例代码
|
||||
# 将以下代码添加到 app.py
|
||||
|
||||
"""
|
||||
在 app.py 中添加以下内容:
|
||||
|
||||
1. 在文件顶部导入:
|
||||
"""
|
||||
|
||||
from mcp_chat_api import mcp_chat_bp
|
||||
|
||||
"""
|
||||
2. 在 Flask app 初始化后注册蓝图:
|
||||
"""
|
||||
|
||||
# 注册 MCP 聊天 API
|
||||
app.register_blueprint(mcp_chat_bp)
|
||||
|
||||
"""
|
||||
3. 确保 CORS 配置允许 Next.js 应用访问:
|
||||
"""
|
||||
|
||||
from flask_cors import CORS
|
||||
|
||||
CORS(app, resources={
|
||||
r"/api/*": {
|
||||
"origins": [
|
||||
"http://localhost:3000", # Next.js 开发环境
|
||||
"http://localhost:3001", # 主应用
|
||||
"http://49.232.185.254:*", # 生产服务器
|
||||
],
|
||||
"supports_credentials": True, # 重要:允许携带 Cookie
|
||||
"allow_headers": ["Content-Type", "Authorization"],
|
||||
"methods": ["GET", "POST", "PUT", "DELETE", "OPTIONS"]
|
||||
}
|
||||
})
|
||||
|
||||
"""
|
||||
4. Session 配置确保跨应用共享:
|
||||
"""
|
||||
|
||||
app.config['SESSION_COOKIE_NAME'] = 'session' # 与现有保持一致
|
||||
app.config['SESSION_COOKIE_HTTPONLY'] = True
|
||||
app.config['SESSION_COOKIE_SAMESITE'] = 'Lax' # 允许跨站点携带
|
||||
app.config['SESSION_COOKIE_PATH'] = '/' # 全路径可用
|
||||
|
||||
# 生产环境额外配置
|
||||
# app.config['SESSION_COOKIE_DOMAIN'] = '.yourdomain.com' # 支持子域
|
||||
# app.config['SESSION_COOKIE_SECURE'] = True # HTTPS only
|
||||
Reference in New Issue
Block a user