Archived
1
0
This repository has been archived on 2024-09-09. You can view files and clone it, but cannot push or open issues or pull requests.
code-server/src/node/routes/health.ts

28 lines
638 B
TypeScript
Raw Normal View History

2020-10-21 01:05:58 +02:00
import { Router } from "express"
import { wss, Router as WsRouter } from "../wsRouter"
2020-10-21 01:05:58 +02:00
export const router = Router()
2020-10-21 01:05:58 +02:00
router.get("/", (req, res) => {
res.json({
status: req.heart.alive() ? "alive" : "expired",
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,
}),
)
})
})
})