forked from rafaeljesus/newww
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
45 lines (39 loc) · 1.02 KB
/
Copy pathindex.js
File metadata and controls
45 lines (39 loc) · 1.02 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
38
39
40
41
42
43
44
45
var _ = require("lodash");
var publicRoutes = require("./public");
var authenticated = require("./authenticated");
var feature = require('../lib/feature-flags');
var routes = publicRoutes.concat(authenticated).filter(function(route) {
if (route.feature) {
return [].concat(route.feature).some(function(feat) {
if (feat[0] == '!') {
return !feature(feat.slice(1));
} else {
return feature(feat);
}
});
} else {
return true;
}
}).reduce(function(routes, route) {
delete route.feature;
// If route defines an array of paths,
// register each as an individual route
if (route.paths) {
route.paths.forEach(function(path) {
var r = _.cloneDeep(route);
delete r.paths;
r.path = path;
routes.push(r);
});
} else {
routes.push(route);
}
return routes;
}, []);
// Convenience method for tests
routes.at = function(name) {
return _.find(this, function(route) {
return name === route.method + " " + route.path;
});
};
module.exports = routes;