Convert routes to Express
This commit is contained in:
@@ -1,22 +1,10 @@
|
||||
import { Heart } from "../heart"
|
||||
import { HttpProvider, HttpProviderOptions, HttpResponse } from "../http"
|
||||
import { Router } from "express"
|
||||
|
||||
/**
|
||||
* Check the heartbeat.
|
||||
*/
|
||||
export class HealthHttpProvider extends HttpProvider {
|
||||
public constructor(options: HttpProviderOptions, private readonly heart: Heart) {
|
||||
super(options)
|
||||
}
|
||||
export const router = Router()
|
||||
|
||||
public async handleRequest(): Promise<HttpResponse> {
|
||||
return {
|
||||
cache: false,
|
||||
mime: "application/json",
|
||||
content: {
|
||||
status: this.heart.alive() ? "alive" : "expired",
|
||||
lastHeartbeat: this.heart.lastHeartbeat,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
router.get("/", (req, res) => {
|
||||
res.json({
|
||||
status: req.heart.alive() ? "alive" : "expired",
|
||||
lastHeartbeat: req.heart.lastHeartbeat,
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user