59 lines
2.3 KiB
Python
59 lines
2.3 KiB
Python
"""注册 insurance 模块路由到 Dify Flask 应用。
|
|
|
|
在 Dify 的 app_factory.py 中添加以下代码:
|
|
try:
|
|
from insurance.register_routes import register_insurance_routes
|
|
register_insurance_routes(app)
|
|
except ImportError as e:
|
|
import logging
|
|
logging.warning(f"Insurance module not loaded: {e}")
|
|
"""
|
|
import logging
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def register_insurance_routes(app):
|
|
"""注册所有 insurance Blueprint 到 Flask app。"""
|
|
from insurance.auth.routes import auth_bp
|
|
from insurance.wecom.routes import wecom_bp
|
|
from insurance.recommend.routes import recommend_bp
|
|
from insurance.permissions.routes import permissions_bp
|
|
from insurance.stats.routes import stats_bp
|
|
from insurance.chat.agent_routes import agent_bp
|
|
from insurance.chat.routes import chat_bp
|
|
|
|
# 使用 /insurance/ 前缀避免与 Dify 的 /api/ 路由冲突
|
|
app.register_blueprint(auth_bp, url_prefix="/insurance/auth")
|
|
app.register_blueprint(chat_bp, url_prefix="/insurance/chat")
|
|
app.register_blueprint(wecom_bp, url_prefix="/insurance/wecom")
|
|
app.register_blueprint(recommend_bp, url_prefix="/insurance/recommend")
|
|
app.register_blueprint(permissions_bp, url_prefix="/insurance/admin")
|
|
app.register_blueprint(stats_bp, url_prefix="/insurance/stats")
|
|
app.register_blueprint(agent_bp, url_prefix="/insurance/agents")
|
|
|
|
# 健康检查(检查实际依赖)
|
|
@app.route("/insurance/health")
|
|
def insurance_health():
|
|
checks = {'status': 'ok', 'service': 'insurance'}
|
|
try:
|
|
from insurance.db.compat import db
|
|
db.session.execute(db.text('SELECT 1'))
|
|
checks['database'] = 'ok'
|
|
except Exception as e:
|
|
checks['database'] = f'error: {str(e)[:100]}'
|
|
checks['status'] = 'degraded'
|
|
try:
|
|
from insurance.db.compat import redis_client
|
|
if redis_client:
|
|
redis_client.ping()
|
|
checks['redis'] = 'ok'
|
|
else:
|
|
checks['redis'] = 'not configured'
|
|
except Exception as e:
|
|
checks['redis'] = f'error: {str(e)[:100]}'
|
|
checks['status'] = 'degraded'
|
|
return checks
|
|
|
|
logger.info("Insurance module routes registered successfully")
|