Add WebSocket observer endpoint for hub state monitoring
- Add /ws/observe WebSocket path for real-time hub state observation - Implement setupObserveServer(httpServer) function that: - Requires secret authentication via observe handshake - Sends immediate snapshot of backends on successful auth - Streams all EventBus events to connected observers - Maintains read-only connections (ignores post-handshake messages) - Properly cleans up listeners on disconnect - Add OBSERVE_SECRET to .env (generate with crypto.randomBytes) - Export OBSERVE_SECRET from config.js - Wire setupObserveServer into index.js alongside existing setupWsServer - Support multiple simultaneous observers - Modified ws-server.js to allow other upgrade handlers (ws-observe, etc) - Add OBSERVE_SECRET to ecosystem.config.js env for pm2 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
83cbe608a0
commit
fc5fa4e16d
5 changed files with 121 additions and 3 deletions
|
|
@ -3,6 +3,9 @@ require('dotenv').config({ path: __dirname + '/.env' });
|
|||
const HUB_SECRET = process.env.HUB_SECRET;
|
||||
if (!HUB_SECRET) throw new Error('HUB_SECRET not set in .env');
|
||||
|
||||
const OBSERVE_SECRET = process.env.OBSERVE_SECRET;
|
||||
if (!OBSERVE_SECRET) throw new Error('OBSERVE_SECRET not set in .env');
|
||||
|
||||
module.exports = {
|
||||
apps: [
|
||||
{
|
||||
|
|
@ -12,7 +15,11 @@ module.exports = {
|
|||
env: {
|
||||
NODE_ENV: 'development',
|
||||
PORT: 3000,
|
||||
HUB_AUTH: JSON.stringify({ 'sample-mcp': HUB_SECRET, 'memory-mcp': HUB_SECRET })
|
||||
HUB_AUTH: JSON.stringify({ 'sample-mcp': HUB_SECRET, 'memory-mcp': HUB_SECRET }),
|
||||
OBSERVE_SECRET: OBSERVE_SECRET,
|
||||
GOOGLE_CLIENT_ID: process.env.GOOGLE_CLIENT_ID || '',
|
||||
GOOGLE_CLIENT_SECRET: process.env.GOOGLE_CLIENT_SECRET || '',
|
||||
OAUTH_ISSUER: process.env.OAUTH_ISSUER || 'https://mcp.arik.work'
|
||||
},
|
||||
max_restarts: 10,
|
||||
restart_delay: 1000,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue