-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
70 lines (63 loc) · 2 KB
/
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
* Copyright 2013 Yahoo! Inc. All rights reserved.
* Licensed under the BSD License.
* http://yuilibrary.com/license/
*/
/**
Middleware to decode the combo url
@param {Object} config.strategy Optional strategy. Defaults to Pathogen.
@return {Array} req.locals.groups Decoded module groups
@return {String} req.locals.type Combo asset type (js or css)
@return {String} req.locals.filter Combo asset filter
**/
exports.decode = require('./lib/middleware/decode');
/**
Validation middleware
@param {Array} res.locals.groups
**/
exports.validate = require('./lib/middleware/validate');
/**
Transform modules into urls
@param {Array} res.locals.groups Array of module groups
@param {String} res.locals.filter Filter
@param {String} res.locals.type Type (js or css)
@param {String} config.yuiBase Base url used to load YUI modules
@param {String} config.appBase Base url used to load application modules
@param {String} config.yuiBaseSecure https version of `yuiBase`
@param {String} config.appBaseSecure https version of `appBase`
@return {Array} res.locals.urls
**/
exports.url = require('./lib/middleware/url');
/**
Create composite middleware.
@method createComposite
@param {Function|Array} middleware* One or more middleware to combine.
@return {Function} Composite middleware.
**/
exports.createComposite = function () {
var args = Array.prototype.slice.apply(arguments),
handlers = [];
args.forEach(function (arg) {
if (Array.isArray(arg)) {
handlers = handlers.concat(arg);
} else {
handlers.push(arg);
}
});
return function (req, res, next) {
function run(index) {
if (index < handlers.length) {
handlers[index](req, res, function (err) {
if (err) {
return next(err);
}
index += 1;
run(index);
});
} else {
next();
}
}
run(0);
};
};