@@ -421,27 +421,29 @@ test('Proxy websocket with custom upstream url', async (t) => {
421421 wss . on ( 'connection' , ( ws , request ) => {
422422 ws . on ( 'message' , ( message , binary ) => {
423423 // Also need save request.url for check from what url the message is coming.
424- serverMessages . push ( [ message . toString ( ) , binary , request . url ] )
424+ serverMessages . push ( [ message . toString ( ) , binary , request . headers . host . split ( ':' ) [ 0 ] , request . url ] )
425425 ws . send ( message , { binary } )
426426 } )
427427 } )
428428
429429 await promisify ( origin . listen . bind ( origin ) ) ( { port : 0 } )
430+ // Host for wsUpstream and for later check.
431+ const host = '127.0.0.1'
430432 // Path for wsUpstream and for later check.
431433 const path = '/some/path'
432434 const server = Fastify ( )
433435 server . register ( proxy , {
434436 upstream : `ws://localhost:${ origin . address ( ) . port } ` ,
435437 // Start proxy with different upstream, added path.
436- wsUpstream : `ws://localhost :${ origin . address ( ) . port } ${ path } ` ,
438+ wsUpstream : `ws://${ host } :${ origin . address ( ) . port } ${ path } ` ,
437439 websocket : true
438440 } )
439441
440442 await server . listen ( { port : 0 } )
441443 t . teardown ( server . close . bind ( server ) )
442444
443445 // Start websocket with different upstream for connect, added path.
444- const ws = new WebSocket ( `ws://localhost :${ server . server . address ( ) . port } ${ path } ` )
446+ const ws = new WebSocket ( `ws://${ host } :${ server . server . address ( ) . port } ${ path } ` )
445447 await once ( ws , 'open' )
446448
447449 const data = [ { message : 'hello' , binary : false } , { message : 'fastify' , binary : true , isBuffer : true } ]
@@ -463,8 +465,8 @@ test('Proxy websocket with custom upstream url', async (t) => {
463465 }
464466 // Also check "path", must be the same.
465467 t . strictSame ( serverMessages , [
466- [ 'hello' , false , path ] ,
467- [ 'fastify' , true , path ]
468+ [ 'hello' , false , host , path ] ,
469+ [ 'fastify' , true , host , path ]
468470 ] )
469471
470472 await Promise . all ( [
0 commit comments