git ssb

1+

dinoworm ๐Ÿ› / catstack



Tree: 9642105bd047078b96b5d68874a78e1c620077e2

Files: 9642105bd047078b96b5d68874a78e1c620077e2 / app / api.js

971 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 return http.createServer(app)
39}
40
41function useAll (app, services) {
42 forEach(services, (service, name) => {
43 app.use(`/${name}`, service)
44 })
45}
46

Built with git-ssb-web