Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/qianlongo/koa2-heartbeat
koa2 心跳检查中间件
https://github.com/qianlongo/koa2-heartbeat
koa koa2
Last synced: 23 days ago
JSON representation
koa2 心跳检查中间件
- Host: GitHub
- URL: https://github.com/qianlongo/koa2-heartbeat
- Owner: qianlongo
- License: mit
- Created: 2018-01-23T14:06:00.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-01-23T15:00:32.000Z (about 7 years ago)
- Last Synced: 2024-12-17T07:19:48.686Z (about 2 months ago)
- Topics: koa, koa2
- Language: JavaScript
- Size: 32.2 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## koa2-heartbeat
> koa2 心跳检查中间件
## 需求背景
> 对于node服务,我们希望有一个与业务无关的路由,可以检查该服务是否”正常运转“,比如访问`http://localhost:3000/heart/check`,返回`heart check passed !!!`
## 使用
**koa2-heartbeat中间件提供两个参数**
1. beatReg
表示要访问的该路由的匹配规则。默认是`/^\/heart\/check/`,也就是以为`/heart/check`开头
2. beatMsg
表示命中上述路由之后,返回的消息内容,默认是`heart check passed !!!`
``` javascript
const Koa = require('koa')
const heartbeat = require('koa2-heartbeat')
const app = new Koa()
const PORT = 3000// 1. 默认用法
app.use(heartBeat())
// 2. 添加自己的规则
app.use(heartBeat(/^\/health\/check/, 'health check passed !!!'))app.listen(PORT, () => {
console.log(`app start at: ${PORT}`)
})```