https://github.com/gavinning/koa-requestid
koa requestid, koa responseid
https://github.com/gavinning/koa-requestid
Last synced: over 1 year ago
JSON representation
koa requestid, koa responseid
- Host: GitHub
- URL: https://github.com/gavinning/koa-requestid
- Owner: gavinning
- Created: 2020-04-09T10:34:49.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-04-09T10:43:23.000Z (over 6 years ago)
- Last Synced: 2025-03-17T19:45:02.858Z (over 1 year ago)
- Language: JavaScript
- Size: 1000 Bytes
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
Koa-RequestId
---
koa requestid, koa responseid
### Install
```sh
npm i @4a/koa-requestid
```
### Usage
```js
const requestid = require('@4a/koa-requestid')
app.use(requestid())
router.get('/', (ctx) => {
console.log(ctx.ResponseId)
})
```
### Notes
```js
// RequestId默认会从headers中查询,查询失败则使用uuid新建
ctx.RequestId = ctx.req.headers.requestId || ctx.req.headers['X-Request-Id'] || uuid.v4().toUpperCase()
// 请求处理完毕RequestId会赋值给ResponseId,下游路由可以按需调用
ctx.ResponseId = ctx.RequestId
```