-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
32 lines (28 loc) · 854 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
const _ = require("lodash");
const traverse = require("traverse");
const requireAll = require("require-all");
const packageAttributes = require("./package.json");
const transformRoutes = routes => traverse(routes)
.reduce((apiRoutes, routeDefinition) => {
const isRoute = _.has(routeDefinition, "method") && _.has(routeDefinition, "path");
if (isRoute) {
apiRoutes.push(routeDefinition);
}
return apiRoutes;
}, []);
const setUpRoutes = directory =>
(server, options, next) => {
const routes = requireAll(directory);
server.route(transformRoutes(routes));
next();
};
module.exports = directory => ({
register: _.merge(
setUpRoutes(directory),
{
attributes: {
pkg: packageAttributes,
},
}
),
});