diff --git a/bin/goldilocks.js b/bin/goldilocks.js index 5346ec5..c03e12b 100755 --- a/bin/goldilocks.js +++ b/bin/goldilocks.js @@ -30,7 +30,7 @@ function mergeSettings(orig, changes) { function fixRawConfig(config) { var updated = false; - if (config.tcp && config.tcp && !Array.isArray(config.tcp)) { + if (config.tcp && config.tcp.bind && !Array.isArray(config.tcp.bind)) { config.tcp.bind = [ config.tcp.bind ]; updated = true; } @@ -87,7 +87,7 @@ function fixRawConfig(config) { updateModules(dom.modules); var strDoms = dom.names.slice().sort().join(','); - var added = config.domain.some(function (existing) { + var added = config.domains.some(function (existing) { if (strDoms !== existing.names.slice().sort().join(',')) { return; } @@ -100,7 +100,7 @@ function fixRawConfig(config) { } var newDom = { - id: crypto.randomBytes(8).toString('hex'), + id: crypto.randomBytes(4).toString('hex'), names: dom.names, modules: {} }; @@ -260,7 +260,11 @@ function fillConfig(config, args) { var mdnsDefaults = { disabled: false, port: 5353, broadcast: '224.0.0.251', ttl: 300 }; config.mdns = Object.assign(mdnsDefaults, config.mdns); - function fillComponent(name, fillBind, fillDomains) { + if (!Array.isArray(config.domains)) { + config.domains = []; + } + + function fillComponent(name, fillBind) { if (!config[name]) { config[name] = {}; } @@ -271,22 +275,11 @@ function fillConfig(config, args) { if (fillBind && !Array.isArray(config[name].bind)) { config[name].bind = []; } - - if (fillDomains) { - if (!Array.isArray(config[name].domains)) { - config[name].domains = []; - } - config[name].domains.forEach(function (domain) { - if (!Array.isArray(domain.modules)) { - domain.modules = []; - } - }); - } } - fillComponent('dns', true, false); - fillComponent('tcp', true, false); - fillComponent('http', false, true); - fillComponent('tls', false, true); + fillComponent('udp', true); + fillComponent('tcp', true); + fillComponent('http', false); + fillComponent('tls', false); if (!config.tls.acme && (args.email || args.agreeTos)) { config.tls.acme = {}; @@ -384,6 +377,9 @@ function run(args) { // TODO spin up multiple workers // TODO use greenlock-cluster cluster.fork(); + }).catch(function (err) { + console.error(err); + process.exit(1); }) ; }