Fastify Request ID Plugin
npm install @fastify-userland/request-id!CI




A plugin for Fastify that adds support for request-id and session-id.
Supports Fastify versions 4.x.
> Support TypeScript
``shellnpm
npm i @fastify-userland/request-id
Usage
`JavaScript
const fastify = require('fastify')()fastify.register(require('@fastify-userland/request-id'), {
// put your options here
})
fastify.get('/', (req, reply) => {
console.log(req.reqID, req.sesID, req.ids)
reply.send({ hello: 'world' }) // => response header has
x-request-id and x-session-id
})fastify.listen(3000)
`You can use it as is without passing any option or you can configure it as explained below.
$3
*
generateHash: Generate hash. For example:`javascript
/**
* @params {"requestID" | "sessionID"} type - will generate type hash
*/
generateHash: (type) => {
if (type === "requestID") {
return req${uuidv4()}
}
if (type === "sessionID") {
return ses${uuidv4()}
}
}
`
requestIDName: request id name - default: x-request-id*
sessionIDName: session id name - default: x-session-id`*Licensed under MIT.