-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathexpress.js
More file actions
executable file
·37 lines (32 loc) · 1.05 KB
/
express.js
File metadata and controls
executable file
·37 lines (32 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
'use strict';
const asyncContext = require('../async-context');
module.exports = {
buildMiddleware: function(provider) {
return function(req, res, next) {
provider.handler(req, res, next);
};
},
mainMiddleware: function(enable, authorize, handleRequest, cls) {
return function(req, res, next) {
handleRequest(enable, authorize, req, res).then((handled) => {
res.locals.miniprofiler = req.miniprofiler;
asyncContext.set(req.miniprofiler);
Object.defineProperty(req, 'miniprofiler', { get: () => asyncContext.get() });
var render = res.render;
res.render = function() {
var renderArguments = arguments;
if (req.miniprofiler) {
req.miniprofiler.step(`Render: ${arguments[0]}`, function() {
render.apply(res, renderArguments);
});
}
else {
render.apply(res, renderArguments);
}
};
if (!handled)
next();
}).catch(next);
};
}
};