chore(deps): update dependency @types/node to v16 (#5170)
* Update Node types to 16 * Update Express core types Fixes a number of conflicts it has with Node 16. * Fix websocket router types It seems req was `any` before so now we have to handle the types. Also it seems the socket is of type `stream.Duplex`, not `net.Socket`. The ws types had to be updated to support the new type. Unfortunately Code still uses the old type so cast for now. In the web socket router just use a cast for the extra properties we add. We could add the types to the Express namespace but I am not sure we really want these commonly accessible so keep with the casts for now. Likely we should use Express's `locals` or something instead. * Add missing return Not sure why it only just now started complaining though. Co-authored-by: Asher <ash@coder.com>
This commit is contained in:
@ -127,7 +127,10 @@ export class CodeServerRouteWrapper {
|
||||
|
||||
private $proxyWebsocket = async (req: WebsocketRequest) => {
|
||||
const wrappedSocket = await this._socketProxyProvider.createProxy(req.ws)
|
||||
this._codeServerMain.handleUpgrade(req, wrappedSocket)
|
||||
// This should actually accept a duplex stream but it seems Code has not
|
||||
// been updated to match the Node 16 types so cast for now. There does not
|
||||
// appear to be any code specific to sockets so this should be fine.
|
||||
this._codeServerMain.handleUpgrade(req, wrappedSocket as net.Socket)
|
||||
|
||||
req.ws.resume()
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { promises as fs } from "fs"
|
||||
import * as net from "net"
|
||||
import * as path from "path"
|
||||
import * as stream from "stream"
|
||||
import * as tls from "tls"
|
||||
import { Emitter } from "../common/emitter"
|
||||
import { generateUuid } from "../common/util"
|
||||
@ -27,10 +28,13 @@ export class SocketProxyProvider {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a socket proxy for TLS sockets. If it's not a TLS socket the
|
||||
* original socket is returned. This will spawn a proxy server on demand.
|
||||
* Create a socket proxy for TLS sockets. If it is not a TLS socket the
|
||||
* original socket or stream is returned. This will spawn a proxy server on
|
||||
* demand.
|
||||
*/
|
||||
public async createProxy(socket: net.Socket): Promise<net.Socket> {
|
||||
public async createProxy(socket: tls.TLSSocket | net.Socket): Promise<net.Socket>
|
||||
public async createProxy(socket: stream.Duplex): Promise<stream.Duplex>
|
||||
public async createProxy(socket: tls.TLSSocket | net.Socket | stream.Duplex): Promise<net.Socket | stream.Duplex> {
|
||||
if (!(socket instanceof tls.TLSSocket)) {
|
||||
return socket
|
||||
}
|
||||
|
@ -8,13 +8,14 @@ export const handleUpgrade = (app: express.Express, server: http.Server): void =
|
||||
server.on("upgrade", (req, socket, head) => {
|
||||
socket.pause()
|
||||
|
||||
req.ws = socket
|
||||
req.head = head
|
||||
req._ws_handled = false
|
||||
const wreq = req as InternalWebsocketRequest
|
||||
wreq.ws = socket
|
||||
wreq.head = head
|
||||
wreq._ws_handled = false
|
||||
|
||||
// Send the request off to be handled by Express.
|
||||
;(app as any).handle(req, new http.ServerResponse(req), () => {
|
||||
if (!req._ws_handled) {
|
||||
;(app as any).handle(wreq, new http.ServerResponse(wreq), () => {
|
||||
if (!wreq._ws_handled) {
|
||||
socket.end("HTTP/1.1 404 Not Found\r\n\r\n")
|
||||
}
|
||||
})
|
||||
|
Reference in New Issue
Block a user