Files: 0409dd215c605012fc66fc9bb693bf445866841b / app / api.js
956 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 cors from 'cors' |
7 | import { map, mapObjIndexed, reduce, toPairs } from 'ramda' |
8 | |
9 | import memory from 'feathers-memory' |
10 | |
11 | const services = Object.assign( |
12 | map( |
13 | (module) => module.service.default, |
14 | bulk(__dirname, '*/service.js') |
15 | ), |
16 | map( |
17 | (module) => module.services.map(m => m.default), |
18 | bulk(__dirname, '*/services/*.js') |
19 | ) |
20 | ) |
21 | |
22 | export default module.exports = createApi |
23 | |
24 | function createApi (config) { |
25 | const app = feathers() |
26 | .use(cors()) |
27 | .configure(rest()) |
28 | .use(bodyParser.json()) |
29 | .use(bodyParser.urlencoded({ extended: true })) |
30 | .configure(hooks()) |
31 | |
32 | useAll(app, services) |
33 | |
34 | return app |
35 | } |
36 | |
37 | function useAll (app, services) { |
38 | return reduce((app, [name, service]) => { |
39 | return app.use(`/${name}`, service) |
40 | }, app, toPairs(services)) |
41 | } |
42 |
Built with git-ssb-web