guanghulab/glada/service-entry.js
Guanghu Domestic Migration d1e47f4565
Some checks failed
自动更新代码和重启 / update-and-restart (push) Has been cancelled
CI检查 + 自动部署 / check (push) Has been cancelled
重启聊天服务 / restart (push) Has been cancelled
CI检查 + 自动部署 / deploy (push) Has been cancelled
chore: import sanitized domestic snapshot for REPO-002
Source snapshot: ca48d3ddf926d79aa138306164169baf764bb829
2026-07-17 15:54:41 +08:00

40 lines
1.2 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env node
/**
* GLADA Service Entry · service-entry.js
*
* 轻量包装器:在 service.js 启动前,自动注入 web 扩展
* CORS · 映川人格对话 · 系统状态仪表盘)
*
* 原理:拦截 Express app.listen(),在监听前注入 web-extensions 路由
* 这样不需要修改 service.js 本体
*
* PM2 入口ecosystem.config.js → script: 'service-entry.js'
*
* 版权:国作登字-2026-A-00037559
*/
'use strict';
const express = require('express');
const _origListen = express.application.listen;
let _patched = false;
// 拦截 app.listen(),在监听前注入 web 扩展
express.application.listen = function(...args) {
if (!_patched) {
_patched = true;
try {
require('./web-extensions')(this);
console.log('[GLADA] ✅ Web扩展已注入CORS · 映川对话 · 系统状态)');
console.log('[GLADA] POST /api/glada/chat/yingchuan 映川对话');
console.log('[GLADA] GET /api/glada/system-status 系统状态');
} catch(e) {
console.warn('[GLADA] ⚠️ web-extensions加载跳过:', e.message);
}
}
return _origListen.apply(this, args);
};
// 启动原始 GLADA 服务
require('./service');