@@ -421,27 +421,29 @@ test('Proxy websocket with custom upstream url', async (t) => {
421
421
wss . on ( 'connection' , ( ws , request ) => {
422
422
ws . on ( 'message' , ( message , binary ) => {
423
423
// 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 ] )
425
425
ws . send ( message , { binary } )
426
426
} )
427
427
} )
428
428
429
429
await promisify ( origin . listen . bind ( origin ) ) ( { port : 0 } )
430
+ // Host for wsUpstream and for later check.
431
+ const host = '127.0.0.1'
430
432
// Path for wsUpstream and for later check.
431
433
const path = '/some/path'
432
434
const server = Fastify ( )
433
435
server . register ( proxy , {
434
436
upstream : `ws://localhost:${ origin . address ( ) . port } ` ,
435
437
// Start proxy with different upstream, added path.
436
- wsUpstream : `ws://localhost :${ origin . address ( ) . port } ${ path } ` ,
438
+ wsUpstream : `ws://${ host } :${ origin . address ( ) . port } ${ path } ` ,
437
439
websocket : true
438
440
} )
439
441
440
442
await server . listen ( { port : 0 } )
441
443
t . teardown ( server . close . bind ( server ) )
442
444
443
445
// 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 } ` )
445
447
await once ( ws , 'open' )
446
448
447
449
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) => {
463
465
}
464
466
// Also check "path", must be the same.
465
467
t . strictSame ( serverMessages , [
466
- [ 'hello' , false , path ] ,
467
- [ 'fastify' , true , path ]
468
+ [ 'hello' , false , host , path ] ,
469
+ [ 'fastify' , true , host , path ]
468
470
] )
469
471
470
472
await Promise . all ( [
0 commit comments