git ssb

1+

dinoworm ๐Ÿ› / vas



Tree: 7e467f6efa8f6320f4c92bbfbe6e905689e0b8eb

Files: 7e467f6efa8f6320f4c92bbfbe6e905689e0b8eb / server.js

1239 bytesRaw
1const setIn = require('set-in')
2const getIn = require('get-in')
3const defined = require('defined')
4
5const defaultSerialize = require('./serialize')
6const walk = require('./walk')
7
8module.exports = createServer
9
10function createServer (services, config, options) {
11 services = defined(services, [])
12 config = defined(config, {})
13 options = defined(options, {})
14
15 var server = {
16 manifest: {},
17 permissions: {},
18 methods: {},
19 handlers: []
20 }
21
22 walk(services, function (service, path) {
23 // merge manifest
24 setIn(server.manifest, path, service.manifest)
25 // merge methods by calling service.init(service, config)
26 setIn(server.methods, path, service.methods && service.methods(server, config))
27 // merge permissions
28 setIn(server.permissions, path, service.permissions && service.permissions(server, config))
29 // merge http handlers
30 if (service.handlers) server.handlers = server.handlers.concat(service.handlers(server, config))
31 if (!server.authenticate && service.authenticate) server.authenticate = service.authenticate(server, config)
32 })
33
34 if (!server.authenticate) server.authenticate = defaultAuthenticate
35
36 return server
37}
38
39function defaultAuthenticate (req, cb) {
40 cb(null, null)
41}
42

Built with git-ssb-web