mirror of
https://github.com/coder/code-server.git
synced 2025-07-28 20:43:24 +08:00
Provide WsRouter to plugins
This commit is contained in:
@ -1,7 +1,10 @@
|
||||
import * as express from "express"
|
||||
import * as http from "http"
|
||||
import * as nodeFetch from "node-fetch"
|
||||
import Websocket from "ws"
|
||||
import * as util from "../src/common/util"
|
||||
import { ensureAddress } from "../src/node/app"
|
||||
import { handleUpgrade } from "../src/node/wsRouter"
|
||||
|
||||
// Perhaps an abstraction similar to this should be used in app.ts as well.
|
||||
export class HttpServer {
|
||||
@ -39,6 +42,13 @@ export class HttpServer {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Send upgrade requests to an Express app.
|
||||
*/
|
||||
public listenUpgrade(app: express.Express): void {
|
||||
handleUpgrade(app, this.hs)
|
||||
}
|
||||
|
||||
/**
|
||||
* close cleans up the server.
|
||||
*/
|
||||
@ -62,6 +72,13 @@ export class HttpServer {
|
||||
return nodeFetch.default(`${ensureAddress(this.hs)}${requestPath}`, opts)
|
||||
}
|
||||
|
||||
/**
|
||||
* Open a websocket against the requset path.
|
||||
*/
|
||||
public ws(requestPath: string): Websocket {
|
||||
return new Websocket(`${ensureAddress(this.hs).replace("http:", "ws:")}${requestPath}`)
|
||||
}
|
||||
|
||||
public port(): number {
|
||||
const addr = this.hs.address()
|
||||
if (addr && typeof addr === "object") {
|
||||
|
Reference in New Issue
Block a user