Files: b11662b22c32dc363fff6ac0ecf64b05f8733f00 / app / api.js
971 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 { mapValues, forEach, assign, reduce } from 'lodash' |
9 | |
10 | const services = assign( |
11 | mapValues( |
12 | bulk(__dirname, '*/service.js'), |
13 | (module) => module.service.default |
14 | ), |
15 | reduce( |
16 | bulk(__dirname, '*/services/*.js'), |
17 | (sofar, module) => assign( |
18 | sofar, |
19 | mapValues( |
20 | module.services, |
21 | m => m.default |
22 | ) |
23 | ), |
24 | {} |
25 | ) |
26 | ) |
27 | |
28 | export function createServer (config) { |
29 | const app = Server() |
30 | .use(cors()) |
31 | .configure(rest()) |
32 | .use(bodyParser.json()) |
33 | .use(bodyParser.urlencoded({ extended: true })) |
34 | .configure(hooks()) |
35 | |
36 | useAll(app, services) |
37 | |
38 | return http.createServer(app) |
39 | } |
40 | |
41 | function useAll (app, services) { |
42 | forEach(services, (service, name) => { |
43 | app.use(`/${name}`, service) |
44 | }) |
45 | } |
46 |
Built with git-ssb-web