52 lines
1.8 KiB
JavaScript
52 lines
1.8 KiB
JavaScript
/**
|
|
* AIBOT 长连接桥(骨架)
|
|
*
|
|
* 本文件职责:仅做本机回环 HTTP 健康检查与转发壳;不拥有业务状态。
|
|
* 端口:环境变量 AIBOT_BRIDGE_PORT(测试默认 8913),绑定 AIBOT_BRIDGE_BIND(默认 127.0.0.1)。
|
|
* 禁止:并存期连接现网 Bot 长连接(现网 8813 已占用);禁止在本进程写工单/六态/Graph。
|
|
* 启动:在 aibot-bridge 目录执行 node server.cjs
|
|
*/
|
|
|
|
"use strict";
|
|
|
|
const http = require("http");
|
|
|
|
const port = Number(process.env.AIBOT_BRIDGE_PORT || 8913);
|
|
const bind = process.env.AIBOT_BRIDGE_BIND || "127.0.0.1";
|
|
const enabled = String(process.env.WECOM_AIBOT_ENABLED || "false").toLowerCase() === "true";
|
|
|
|
const server = http.createServer((req, res) => {
|
|
// 只处理短请求;真实 AIBOT 帧转发后续迭代。请求线程不做业务。
|
|
if (req.url === "/health" || req.url === "/health/") {
|
|
const body = JSON.stringify({
|
|
status: "UP",
|
|
service: "aibot-bridge",
|
|
bind,
|
|
port,
|
|
wecomAibotEnabled: enabled,
|
|
note: enabled
|
|
? "enabled flag on — 仍须确认未与现网双连"
|
|
: "scaffold: Bot 长连接默认关闭(并存期禁止再连)",
|
|
});
|
|
res.writeHead(200, { "Content-Type": "application/json; charset=utf-8" });
|
|
res.end(body);
|
|
return;
|
|
}
|
|
|
|
res.writeHead(404, { "Content-Type": "application/json; charset=utf-8" });
|
|
res.end(JSON.stringify({ error: "not_found", path: req.url }));
|
|
});
|
|
|
|
server.listen(port, bind, () => {
|
|
// eslint-disable-next-line no-console
|
|
console.log(
|
|
`[aibot-bridge] listening http://${bind}:${port}/health wecomAibotEnabled=${enabled}`
|
|
);
|
|
if (enabled) {
|
|
// eslint-disable-next-line no-console
|
|
console.warn(
|
|
"[aibot-bridge] WECOM_AIBOT_ENABLED=true:请确认已停现网桥且不会双连同一 Bot"
|
|
);
|
|
}
|
|
});
|