Files: ef61c94641c6cd211cbc6cc00392550cc09c8241 / config.js
1204 bytesRaw
1 | const nest = require('depnest') |
2 | const Config = require('ssb-config/inject') |
3 | const Path = require('path') |
4 | const merge = require('lodash/merge') |
5 | |
6 | exports.gives = nest('config.sync.load') |
7 | exports.create = (api) => { |
8 | var config |
9 | return nest('config.sync.load', () => { |
10 | if (config) return config |
11 | |
12 | console.log('LOADING config') |
13 | config = Config(process.env.ssb_appname || 'ssb') |
14 | |
15 | config = addSockets(config) |
16 | config = fixLocalhost(config) |
17 | |
18 | return config |
19 | }) |
20 | } |
21 | |
22 | function addSockets (config) { |
23 | if (process.platform === 'win32') return config |
24 | |
25 | const pubkey = config.keys.id.slice(1).replace(`.${config.keys.curve}`, '') |
26 | return merge( |
27 | config, |
28 | { |
29 | connections: { |
30 | incoming: { unix: [{ scope: 'local', transform: 'noauth', server: true }] } |
31 | }, |
32 | remote: `unix:${Path.join(config.path, 'socket')}:~noauth:${pubkey}` // overwrites |
33 | } |
34 | ) |
35 | } |
36 | |
37 | function fixLocalhost (config) { |
38 | if (process.platform !== 'win32') return config |
39 | |
40 | // without this host defaults to :: which doesn't work on windows 10? |
41 | config.connections.incoming.net[0].host = '127.0.0.1' |
42 | config.connections.incoming.ws[0].host = '127.0.0.1' |
43 | config.host = '127.0.0.1' |
44 | return config |
45 | } |
46 |
Built with git-ssb-web