Archived
1
0

Add health websocket

This is used by some of our services.
This commit is contained in:
Asher
2021-01-28 12:47:50 -06:00
parent f136a60093
commit b13db3124b
3 changed files with 21 additions and 0 deletions

View File

@ -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,
}),
)
})
})
})

View File

@ -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)