-
Notifications
You must be signed in to change notification settings - Fork 2
/
array.js
57 lines (48 loc) · 1.38 KB
/
array.js
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
var express = require('express');
var emt = require('../'); // require('express-middleware-timer');
var app = express();
/***
* In this example, I'm going to call middleware in
* the route. So I'm going to create an array of
* middleware, instrument them and then unshift init
* and push report.
*
* See: examples/simple.js for a more basic example.
***************************************************/
/***
* time slow middleware
* - non-anon middleware don't require names
***************************************************/
function slowMiddleware(req, res, next) {
setTimeout(function() {
next();
}, 200);
}
/***
* time fast middleware
***************************************************/
function fastMiddleware(req, res, next) {
next();
};
/***
* Define middleware stack with instrumentation.
***************************************************/
var middlewares = emt.instrument([
slowMiddleware,
fastMiddleware
]);
/***
* Add init to the beginning of the middleware stack.
***************************************************/
middlewares.unshift(emt.init());
/***
* Route contain middleware.
***************************************************/
app.get('/', middlewares, function(req,res) {
res.send('hello world');
});
/***
* Start
***************************************************/
app.listen(3000);
console.log('Listening on port 3000');