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