Commit 32dce475ec91f2a5a01cdc3c18e065cdec7125dd
Merge config object and use variable curve string
This commit resolves an issue where a chain of of properties throws: TypeError: Cannot read property 'incoming' of undefined Using `_.merge()` instead merges the two objects, which makes changes to nested objects without any errors. This commit also replaces the hardcoded "ed25519" curve with a variable, which should be tolerant of new curves that may be used in the future.Christian Bundy committed on 9/12/2018, 5:49:22 PM
Parent: ba7b522a22c401fac1d4b07d93169c95b32cc16d
Files changed
config.js | changed |
config.js | ||
---|---|---|
@@ -1,8 +1,9 @@ | ||
1 | 1 … | const nest = require('depnest') |
2 | 2 … | const Config = require('ssb-config/inject') |
3 | 3 … | const ssbKeys = require('ssb-keys') |
4 | 4 … | const Path = require('path') |
5 … | +const merge = require('lodash/merge') | |
5 | 6 … | |
6 | 7 … | const appName = process.env.ssb_appname || 'ssb' |
7 | 8 … | const opts = appName === 'ssb' |
8 | 9 … | ? null |
@@ -14,14 +15,19 @@ | ||
14 | 15 … | return nest('config.sync.load', () => { |
15 | 16 … | if (!config) { |
16 | 17 … | console.log('LOADING config') |
17 | 18 … | config = Config(appName, opts) |
18 | - config.keys = ssbKeys.loadOrCreateSync(Path.join(config.path, 'secret')) | |
19 | 19 … | |
20 | - if (!config.connections.incoming.unix) | |
21 | - config.connections.incoming.unix = [{ "scope": "local", "transform": "noauth" }] | |
20 … | + const keys = ssbKeys.loadOrCreateSync(Path.join(config.path, 'secret')) | |
21 … | + const pubkey = keys.id.slice(1).replace(`.${keys.curve}`, '') | |
22 | 22 … | |
23 | - config.remote = `unix:${Path.join(config.path, 'socket')}:~noauth:${config.keys.id.slice(1).replace('.ed25519', '')}` | |
23 … | + config = merge(config, { | |
24 … | + connections: { | |
25 … | + incoming: { unix: [{ 'scope': 'local', 'transform': 'noauth' }] } | |
26 … | + }, | |
27 … | + keys, | |
28 … | + remote: `unix:${Path.join(config.path, 'socket')}:~noauth:${pubkey}` | |
29 … | + }) | |
24 | 30 … | } |
25 | 31 … | return config |
26 | 32 … | }) |
27 | 33 … | } |
Built with git-ssb-web