@@ -661,7 +661,7 @@ const initializeProxy = async function ({
661
661
return proxy . web ( req , res , options )
662
662
} ,
663
663
// @ts -expect-error TS(7006) FIXME: Parameter 'req' implicitly has an 'any' type.
664
- ws : ( req , socket , head ) => proxy . ws ( req , socket , head ) ,
664
+ ws : ( req , socket , head , options ) => proxy . ws ( req , socket , head , options ) ,
665
665
}
666
666
667
667
return handlers
@@ -876,8 +876,15 @@ export const startProxy = async function ({
876
876
const primaryServer = settings . https
877
877
? https . createServer ( { cert : settings . https . cert , key : settings . https . key } , onRequestWithOptions )
878
878
: http . createServer ( onRequestWithOptions )
879
- const onUpgrade = function onUpgrade ( req : http . IncomingMessage , socket : Duplex , head : Buffer ) {
880
- proxy . ws ( req , socket , head )
879
+ const onUpgrade = async function onUpgrade ( req : http . IncomingMessage , socket : Duplex , head : Buffer ) {
880
+ const match = await rewriter ( req )
881
+ if ( match && ! match . force404 && isExternal ( match ) ) {
882
+ const reqUrl = reqToURL ( req , req . url )
883
+ const dest = new URL ( match . to , `${ reqUrl . protocol } //${ reqUrl . host } ` )
884
+ const destURL = stripOrigin ( dest )
885
+ return proxy . ws ( req , socket , head , { target : dest . origin , changeOrigin : true , pathRewrite : ( ) => destURL } )
886
+ }
887
+ return proxy . ws ( req , socket , head , { } )
881
888
}
882
889
883
890
primaryServer . on ( 'upgrade' , onUpgrade )
2 commit comments
github-actions[bot] commentedon May 29, 2024
📊 Benchmark results
github-actions[bot] commentedon May 29, 2024
📊 Benchmark results