bridge-node-server/node_server/dev_api/uniqueIdMiddleware.js
Martin Donnelly 57bd6c8e6a init
2018-06-24 21:15:03 +01:00

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();
}