Created
August 12, 2022 01:49
-
-
Save damiancipolat/ddcdc36401e5efbf9ea0665748fa16d6 to your computer and use it in GitHub Desktop.
Hapi JS plugin for inject request-id in request lifecycle.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { v4 as uuidv4 } from 'uuid'; | |
const register = (server, options) => { | |
server.ext({ | |
type: 'onRequest', | |
method: (request, h) => { | |
request.id = request.headers['x-request-id']||uuidv4(); | |
return h.continue; | |
} | |
}); | |
}; | |
const plugin = { | |
pkg: require('../../../package.json'), | |
name: 'zettle-request-id', | |
version: '0.0.1', | |
register | |
}; | |
export default plugin; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment