File tree Expand file tree Collapse file tree 1 file changed +9
-4
lines changed
Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -89,12 +89,17 @@ function Server (opts) {
8989 if ( opts . ws !== false ) {
9090 if ( ! self . http ) {
9191 self . http = http . createServer ( )
92- self . http . on ( 'request' , function ( req , res ) {
93- res . statusCode = 404
94- res . end ( '404 Not Found' )
95- } )
9692 self . http . on ( 'error' , function ( err ) { self . _onError ( err ) } )
9793 self . http . on ( 'listening' , onListening )
94+
95+ // Add default http request handler if user does not add one on same tick
96+ process . nextTick ( function ( ) {
97+ if ( self . http . listenerCount ( 'request' ) > 0 ) return
98+ self . http . on ( 'request' , function ( req , res ) {
99+ res . statusCode = 404
100+ res . end ( '404 Not Found' )
101+ } )
102+ } )
98103 }
99104 self . ws = new WebSocketServer ( { server : self . http } )
100105 self . ws . address = self . http . address . bind ( self . http )
You can’t perform that action at this time.
0 commit comments