, , , - , . , , , - ( randomstring). , , . , res.locals( )
:
var random = require('randomstring');
var generate = function(){
var dt = new Date();
return random.generate() + dt.toISOString();
}
module.exports.createID = function(req, res, next){
res.locals.flowid = generate();
next();
}
, :
var flowcontrol = require('flow.js');
var middleware = require('middleware.js');
app.use(flowcontrol.createID);
app.get('/api/awesomeresource', middlewares.first, middlewares.second);
, , :
module.exports.first = function(req, res, next){
console.log(res.locals.flowid + " - First i did this...");
next();
}
module.exports.second = function(req, res, next){
console.log(res.locals.flowid + " - Second i did this...");
res.sendStatus(200);
}
GET /api/awesomeresource HTTP/1.1
:
> R90A56nEmZWYK73NOEVbWv2RS6DolO4D2017-12-07T10:29:39.291Z - First i did
> this...
> R90A56nEmZWYK73NOEVbWv2RS6DolO4D2017-12-07T10:29:39.291Z -
> Second i did this...
, -.