git ssb

1+

dinoworm ๐Ÿ› / catstack



Tree: 8063afb16b2de577b87116ddc34cf98c5b26d67e

Files: 8063afb16b2de577b87116ddc34cf98c5b26d67e / app / api.js

1046 bytesRaw
1const bulk = require('bulk-require')
2import http from 'http'
3import Server from 'feathers'
4import hooks from 'feathers-hooks'
5import rest from 'feathers-rest'
6import bodyParser from 'body-parser'
7import cors from 'cors'
8import { mapValues, forEach, assign, reduce } from 'lodash'
9
10const 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
28export 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 // must call app.setup() because not calling app.listen()
39 app.setup()
40
41 return http.createServer(app)
42}
43
44function useAll (app, services) {
45 forEach(services, (service, name) => {
46 app.use(`/${name}`, service)
47 })
48}
49

Built with git-ssb-web