You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Aug 20, 2024. It is now read-only.
Hello, I'm using koa-better-http-proxy, and the following code to support websocket upgrade:
/** * Create a WebSocket server. * @param server Server */createWebSocketServer(server: http.Server|https.Server|http2.Http2SecureServer){server.on('upgrade',(req: http.IncomingMessage,sock: net.Socket,head: Buffer)=>{server.emit('request',req,newUpgradableResponse(sock,head));});constcreateContext=this.app.createContext;this.app.createContext=(req: http.IncomingMessage,res: http.ServerResponse|UpgradableResponse)=>{constctx: Koa.Context=createContext.call(this.app,req,res);if(resinstanceofUpgradableResponse){ctx.ws=true;ctx.upgrade=()=>res.upgrade(req);}returnctx;};}
The UpgradeableReponse provides a upgrade method which returns a ws.WebSocket instance. Then the method is copied in the overridden createContext to be made accessible in ctx. ctx.ws is also set to true to indicate this connection is upgradable.
However, I can't figure out how to implement this in koa-better-http-proxy and act like nginx's proxy_pass.
The text was updated successfully, but these errors were encountered:
cloudwindy
changed the title
How to Handle WebSocket Upgrade Request?
Handling WebSocket Upgrade Request
Jan 25, 2022
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Hello, I'm using koa-better-http-proxy, and the following code to support websocket upgrade:
The
UpgradeableReponse
provides a upgrade method which returns aws.WebSocket
instance. Then the method is copied in the overriddencreateContext
to be made accessible inctx
.ctx.ws
is also set to true to indicate this connection is upgradable.However, I can't figure out how to implement this in
koa-better-http-proxy
and act like nginx'sproxy_pass
.The text was updated successfully, but these errors were encountered: