forked from lsongdev/kelp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
40 lines (39 loc) · 863 Bytes
/
index.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
'use strict';
/**
* [exports Kelp]
* @return {[type]} [description]
*/
function Kelp() {
/**
* [app http server handler]
* @param {[type]} req [request]
* @param {[type]} res [response]
* @return {[type]} [undefined]
*/
function app(req, res) {
var self = this, i = -1, mw;
(async function next(err) {
mw = app.stack[++i];
return mw && mw.call(self, req, res, next, err);
})();
};
/**
* [stack middlewares]
* @type {Array}
*/
app.stack = [];
/**
* [function push middleware to stack]
* @param {[type]} middlewares [middlewares]
* @return {[type]} [application]
*/
app.use = function (middlewares) {
this.stack = [].concat.apply(this.stack, arguments);
return app;
};
/**
* expose
*/
return app.use.apply(app, arguments);
};
module.exports = Kelp;