mirror of
https://github.com/cdr/code-server.git
synced 2025-12-25 09:55:32 +01:00
* Update Code to 1.94.2 * Convert from yarn to npm This is to match VS Code. We were already partially using npm for the releases so this is some nice alignment. * Update caniuse-lite This was complaining on every unit test. * Update eslint I was having a bunch of dependency conflicts and eslint seemed to be the culprit so I just removed it and set it up again, since it seems things have changed quite a bit. * Update test dependencies I was getting oom when running the unit tests...updating seems to work. * Remove package.json `scripts` property in release The new pre-install script was being included, which is dev-only. This was always the intent; did not realize jq's merge was recursive. * Remove jest and devDependencies in release as well * Update test extension dependencies This appears to be conflicting with the root dependencies. * Fix playwright exec npm does not let you run binaries like yarn does, as far as I know. * Fix import of server-main.js * Fix several tests by waiting for selectors
57 lines
1.6 KiB
TypeScript
57 lines
1.6 KiB
TypeScript
import * as express from "express"
|
|
import * as expressCore from "express-serve-static-core"
|
|
import * as http from "http"
|
|
import Websocket from "ws"
|
|
import * as pluginapi from "../../typings/pluginapi"
|
|
|
|
export const handleUpgrade = (app: express.Express, server: http.Server): void => {
|
|
server.on("upgrade", (req, socket, head) => {
|
|
socket.pause()
|
|
|
|
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(wreq, new http.ServerResponse(wreq), () => {
|
|
if (!wreq._ws_handled) {
|
|
socket.end("HTTP/1.1 404 Not Found\r\n\r\n")
|
|
}
|
|
})
|
|
})
|
|
}
|
|
|
|
interface InternalWebsocketRequest extends pluginapi.WebsocketRequest {
|
|
_ws_handled: boolean
|
|
}
|
|
|
|
export class WebsocketRouter {
|
|
public readonly router = express.Router()
|
|
|
|
/**
|
|
* Handle a websocket at this route. Note that websockets are immediately
|
|
* paused when they come in.
|
|
*
|
|
* If the origin header exists it must match the host or the connection will
|
|
* be prevented.
|
|
*/
|
|
public ws(route: expressCore.PathParams, ...handlers: pluginapi.WebSocketHandler[]): void {
|
|
this.router.get(
|
|
route,
|
|
...handlers.map((handler) => {
|
|
const wrapped: express.Handler = (req, res, next) => {
|
|
;(req as InternalWebsocketRequest)._ws_handled = true
|
|
return handler(req as pluginapi.WebsocketRequest, res, next)
|
|
}
|
|
return wrapped
|
|
}),
|
|
)
|
|
}
|
|
}
|
|
|
|
export function Router(): WebsocketRouter {
|
|
return new WebsocketRouter()
|
|
}
|
|
|
|
export const wss = new Websocket.Server({ noServer: true })
|