Files: 7565f0a3a2bb8400488b3acd6395b0306df1c5df / app / api.js
845 bytesRaw
1 | const bulk = require('bulk-require') |
2 | import feathers from 'feathers' |
3 | import hooks from 'feathers-hooks' |
4 | import rest from 'feathers-rest' |
5 | import bodyParser from 'body-parser' |
6 | import { map, mapObjIndexed, reduce, toPairs } from 'ramda' |
7 | |
8 | const services = { |
9 | ...map( |
10 | (module) => module.service.default, |
11 | bulk(__dirname, '*/service.js') |
12 | ), |
13 | ...map( |
14 | (module) => module.services.map(m => m.default), |
15 | bulk(__dirname, '*/services/*.js') |
16 | ) |
17 | } |
18 | |
19 | export default function createServer (config) { |
20 | const app = feathers() |
21 | .configure(rest()) |
22 | .configure(hooks()) |
23 | .use(bodyParser.json()) |
24 | .use(bodyParser.urlencoded({ extended: true })) |
25 | |
26 | useAll(app, services) |
27 | |
28 | return app |
29 | } |
30 | |
31 | function useAll (app, services) { |
32 | return reduce((app, [name, service]) => { |
33 | return app.use(`/${name}`, service) |
34 | }, app, toPairs(services)) |
35 | } |
36 |
Built with git-ssb-web