File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed
Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -183,15 +183,36 @@ export function registerWebhookRoutes(app: express.Application) {
183183 set . add ( res ) ;
184184 sseClients . set ( userPath , set ) ;
185185
186+ // Log connection for debugging (shows remote address and total clients for the path)
187+ try {
188+ const remote = ( req . ip || ( req . socket && ( req . socket . remoteAddress || req . socket . remoteFamily ) ) || 'unknown' ) ;
189+ console . log ( `SSE connected: path=${ userPath } remote=${ remote } clients=${ set . size } ` ) ;
190+ } catch ( err ) {
191+ // ignore logging errors
192+ }
193+
186194 req . on ( 'close' , ( ) => {
187195 const clients = sseClients . get ( userPath ) ;
188196 if ( clients ) {
189197 clients . delete ( res ) ;
190198 if ( clients . size === 0 ) sseClients . delete ( userPath ) ;
191199 }
200+ try {
201+ const remote = ( req . ip || ( req . socket && ( req . socket . remoteAddress || req . socket . remoteFamily ) ) || 'unknown' ) ;
202+ console . log ( `SSE disconnected: path=${ userPath } remote=${ remote } remaining=${ sseClients . get ( userPath ) ?. size || 0 } ` ) ;
203+ } catch ( err ) {
204+ // ignore
205+ }
192206 } ) ;
193207 } ) ;
194208
209+ // Diagnostic: number of SSE clients for a given webhook path
210+ app . get ( '/__diag/webhook-sse/:userPath' , ( req : Request , res : Response ) => {
211+ const userPath = req . params . userPath ;
212+ const clients = sseClients . get ( userPath ) || new Set < Response > ( ) ;
213+ return res . json ( { path : userPath , clients : clients . size , keys : Array . from ( sseClients . keys ( ) ) } ) ;
214+ } ) ;
215+
195216 // Diagnostic endpoint to inspect last webhook request for a path
196217 app . get ( '/__diag/webhook/:userPath' , ( req : Request , res : Response ) => {
197218 const userPath = req . params . userPath ;
You can’t perform that action at this time.
0 commit comments