Add health websocket
This is used by some of our services.
This commit is contained in:
parent
f136a60093
commit
b13db3124b
@ -1,4 +1,5 @@
|
||||
import { Router } from "express"
|
||||
import { wss, Router as WsRouter } from "../wsRouter"
|
||||
|
||||
export const router = Router()
|
||||
|
||||
@ -8,3 +9,19 @@ router.get("/", (req, res) => {
|
||||
lastHeartbeat: req.heart.lastHeartbeat,
|
||||
})
|
||||
})
|
||||
|
||||
export const wsRouter = WsRouter()
|
||||
|
||||
wsRouter.ws("/", async (req) => {
|
||||
wss.handleUpgrade(req, req.socket, req.head, (ws) => {
|
||||
ws.on("message", () => {
|
||||
ws.send(
|
||||
JSON.stringify({
|
||||
event: "health",
|
||||
status: req.heart.alive() ? "alive" : "expired",
|
||||
lastHeartbeat: req.heart.lastHeartbeat,
|
||||
}),
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -133,6 +133,7 @@ export const register = async (
|
||||
wsApp.use("/vscode", vscode.wsRouter.router)
|
||||
|
||||
app.use("/healthz", health.router)
|
||||
wsApp.use("/healthz", health.wsRouter.router)
|
||||
|
||||
if (args.auth === AuthType.Password) {
|
||||
app.use("/login", login.router)
|
||||
|
@ -1,6 +1,7 @@
|
||||
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 => {
|
||||
@ -48,3 +49,5 @@ export class WebsocketRouter {
|
||||
export function Router(): WebsocketRouter {
|
||||
return new WebsocketRouter()
|
||||
}
|
||||
|
||||
export const wss = new Websocket.Server({ noServer: true })
|
||||
|
Reference in New Issue
Block a user