Use it for Kubernetes liveness & readiness checks. The middleware opens a HTTP server on port 3001. To check, open the http://localhost:3001/live & http://localhost:3001/ready URL.
{
"state": "up",
"uptime": 7.419,
"timestamp": 1562790370161
}
The
state
can be"starting"
(503),"up"
(200),"stopping"
(503) or"down"
(503).
Load with default options
// moleculer.config.js
const HealthMiddleware = require("./health-check.middleware.js");
module.exports = {
middlewares: [
HealthMiddleware()
]
};
Load with custom options
// moleculer.config.js
const HealthMiddleware = require("./health-check.middleware.js");
module.exports = {
middlewares: [
HealthMiddleware({
port: 3333,
readiness: {
path: "/ready"
},
liveness: {
path: "/live"
}
})
]
};
apiVersion: apps/v1
kind: Deployment
metadata:
name: greeter
spec:
selector:
matchLabels:
app: greeter
replicas: 1
template:
metadata:
labels:
app: greeter
spec:
containers:
- name: greeter
image: moleculer/demo:1.4.2
livenessProbe:
httpGet:
path: /live
port: 3001
readinessProbe:
httpGet:
path: /ready
port: 3001
@icebob I think there can be a issue with node >= 16 since the request handler is registered twice:
createServer(handler)
server.on('request', handler)
The
server.on
line should be omitted.