22 lines
593 B
JavaScript
22 lines
593 B
JavaScript
/**
|
|
* @fileOverview Add a unique id to every request so we can correlate logs
|
|
*/
|
|
'use strict';
|
|
|
|
const uuidv4 = require('uuid/v4');
|
|
|
|
module.exports = uniqueIdMiddleware;
|
|
|
|
/**
|
|
* Middleware function to add a unique ID (random UUID v4) to each request. This
|
|
* can then be added to the logging to correlate logs from the same call.
|
|
*
|
|
* @param {Object} req - Express request object
|
|
* @param {Object} res - Express response object
|
|
* @param {Object} next - Callback to continue processing
|
|
*/
|
|
function uniqueIdMiddleware(req, res, next) {
|
|
req.bridgeUniqueId = uuidv4();
|
|
next();
|
|
}
|