UNPKG

554 BJavaScriptView Raw
1/**
2 * Request Identifer.
3 * Creates a shortened unique id that can be converted into a date object.
4 */
5const { timeCoded } = require('./../namespace/token');
6const { chalk, time } = require('./../namespace/console');
7
8module.exports = class RequestIdentifer {
9
10 constructor (project) {
11 this.logging = require(project.configPath).logHTTP;
12 }
13
14 id (req, res, next) {
15 req.id = timeCoded();
16 if (this.logging) {
17 time(`Timing ${req.id}`);
18 chalk.info(`Request ${req.id} << ${req.method}: ${req.url}`);
19 }
20 next();
21 }
22
23}