|
|
|
|
@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
|
|
|
|
|
'use strict'; |
|
|
|
|
// DSH PRO - server.js
|
|
|
|
|
// DSH memory - server.js
|
|
|
|
|
// 本地桥接服务:HTTP 路由 + Bearer token 鉴权 + 限流 + 审计。
|
|
|
|
|
// 仅绑定 127.0.0.1。零 npm 依赖。启动:node server.js(需先在 config.json 填写 token)。
|
|
|
|
|
// 预留 /mcp 路由分支:将来可在同一 handler 层挂 streamable-HTTP MCP 端点,
|
|
|
|
|
@ -22,11 +22,11 @@ let config;
@@ -22,11 +22,11 @@ let config;
|
|
|
|
|
try { |
|
|
|
|
config = loadConfig(BRIDGE_DIR); |
|
|
|
|
} catch (err) { |
|
|
|
|
console.error('[DSH PRO] config load failed:', err.message); |
|
|
|
|
console.error('[DSH memory] config load failed:', err.message); |
|
|
|
|
process.exit(1); |
|
|
|
|
} |
|
|
|
|
if (!config.token || String(config.token).length < 32) { |
|
|
|
|
console.error('[DSH bridge] STARTUP: token missing or short, exiting'); |
|
|
|
|
console.error('[DSH memory] STARTUP: token missing or short, exiting'); |
|
|
|
|
process.exit(1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -385,21 +385,21 @@ const server = http.createServer(async (req, res) => {
@@ -385,21 +385,21 @@ const server = http.createServer(async (req, res) => {
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
server.listen(config.port, '127.0.0.1', () => { |
|
|
|
|
console.log(`[DSH PRO] bridge listening on http://127.0.0.1:${config.port}`); |
|
|
|
|
console.log(`[DSH memory] bridge listening on http://127.0.0.1:${config.port}`); |
|
|
|
|
// ensureStateDir on startup: create .dsh-memory/ in every allowedRoot
|
|
|
|
|
for (const root of config.allowedRoots) { |
|
|
|
|
const sd = stateDir.ensureStateDir(root); |
|
|
|
|
if (sd) console.log('[DSH memory] state dir ready: ' + sd); |
|
|
|
|
else console.log('[DSH memory] state dir failed for root: ' + root); |
|
|
|
|
} |
|
|
|
|
console.log(`[DSH PRO] allowedRoots: ${config.allowedRoots.join(' ; ')}`); |
|
|
|
|
console.log(`[DSH memory] allowedRoots: ${config.allowedRoots.join(' ; ')}`); |
|
|
|
|
const probe = dshProbe(config); |
|
|
|
|
console.log(`[DSH PRO] dsh runtime: ${probe.binFound ? 'found' : 'NOT FOUND'} (${probe.bin || '-'})`); |
|
|
|
|
console.log(`[DSH memory] dsh runtime: ${probe.binFound ? 'found' : 'NOT FOUND'} (${probe.bin || '-'})`); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
process.on('uncaughtException', (err) => { |
|
|
|
|
console.error('[DSH PRO] uncaught:', err && err.stack); |
|
|
|
|
console.error('[DSH memory] uncaught:', err && err.stack); |
|
|
|
|
}); |
|
|
|
|
process.on('unhandledRejection', (err) => { |
|
|
|
|
console.error('[DSH PRO] unhandledRejection:', String(err)); |
|
|
|
|
console.error('[DSH memory] unhandledRejection:', String(err)); |
|
|
|
|
}); |
|
|
|
|
|