Skip to content

Commit 0e56c34

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 0e56c34

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/node/wsRouter.ts

+6-5
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

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { field, Level, Logger } from "@coder/logger"
55
import * as express from "express"
66
import * as expressCore from "express-serve-static-core"
77
import ProxyServer from "http-proxy"
8-
import * as net from "net"
8+
import * as stream from "stream"
99
import Websocket from "ws"
1010

1111
/**
@@ -97,7 +97,7 @@ export declare class HttpError extends Error {
9797
}
9898

9999
export interface WebsocketRequest extends express.Request {
100-
ws: net.Socket
100+
ws: stream.Duplex
101101
head: Buffer
102102
}
103103

0 commit comments

Comments
 (0)