1.0.0 • Published 4 years ago

@4a/koa-requestid v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

Koa-RequestId

koa requestid, koa responseid

Install

npm i @4a/koa-requestid

Usage

const requestid = require('@4a/koa-requestid')

app.use(requestid())

router.get('/', (ctx) => {
    console.log(ctx.ResponseId)
})

Notes

// RequestId默认会从headers中查询,查询失败则使用uuid新建
ctx.RequestId = ctx.req.headers.requestId || ctx.req.headers['X-Request-Id'] || uuid.v4().toUpperCase()

// 请求处理完毕RequestId会赋值给ResponseId,下游路由可以按需调用
ctx.ResponseId = ctx.RequestId