Skip to content

Commit 8a09918

Browse files
committed
Fix websocket router types
It seems req was any before so now we have to handle the types.
1 parent e05404a commit 8a09918

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/node/wsRouter.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ export const handleUpgrade = (app: express.Express, server: http.Server): void =
88
server.on("upgrade", (req, socket, head) => {
99
socket.pause()
1010

11-
req.ws = socket
12-
req.head = head
13-
req._ws_handled = false
11+
const wreq = req as InternalWebsocketRequest
12+
wreq.ws = socket
13+
wreq.head = head
14+
wreq._ws_handled = false
1415

1516
// Send the request off to be handled by Express.
16-
;(app as any).handle(req, new http.ServerResponse(req), () => {
17-
if (!req._ws_handled) {
17+
;(app as any).handle(wreq, new http.ServerResponse(wreq), () => {
18+
if (!wreq._ws_handled) {
1819
socket.end("HTTP/1.1 404 Not Found\r\n\r\n")
1920
}
2021
})

typings/pluginapi.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as express from "express"
66
import * as expressCore from "express-serve-static-core"
77
import ProxyServer from "http-proxy"
88
import * as net from "net"
9+
import * as stream from "stream"
910
import Websocket from "ws"
1011

1112
/**
@@ -97,7 +98,7 @@ export declare class HttpError extends Error {
9798
}
9899

99100
export interface WebsocketRequest extends express.Request {
100-
ws: net.Socket
101+
ws: net.Socket | stream.Duplex
101102
head: Buffer
102103
}
103104

0 commit comments

Comments
 (0)