git ssb

1+

dinoworm ๐Ÿ› / catstack



Tree: 83061f88db26bb624bef7833f89b2565ee2d4031

Files: 83061f88db26bb624bef7833f89b2565ee2d4031 / app / api.js

933 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 { map, mapObjIndexed, reduce, toPairs } from 'ramda'
9
10const 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
21export 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
34function 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