Skip to content

Instantly share code, notes, and snippets.

@damiancipolat
Created August 12, 2022 01:49
Show Gist options
  • Save damiancipolat/ddcdc36401e5efbf9ea0665748fa16d6 to your computer and use it in GitHub Desktop.
Save damiancipolat/ddcdc36401e5efbf9ea0665748fa16d6 to your computer and use it in GitHub Desktop.
Hapi JS plugin for inject request-id in request lifecycle.
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