From d04b750f87d8c5cf894e57564e3250753602a504 Mon Sep 17 00:00:00 2001 From: tigerbot Date: Wed, 4 Oct 2017 18:26:27 -0600 Subject: [PATCH] changed the default config --- bin/goldilocks.js | 49 +++++++++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/bin/goldilocks.js b/bin/goldilocks.js index 908da13..6b71c75 100755 --- a/bin/goldilocks.js +++ b/bin/goldilocks.js @@ -148,26 +148,42 @@ var tcpProm; function fillConfig(config, args) { config.debug = config.debug || args.debug; - if (!config.dns) { - config.dns = { bind: [ 53 ], modules: [{ name: 'proxy', port: 3053 }] }; - } if (!config.ddns) { config.ddns = { enabled: false }; } - // Use Object.assign to add any properties needed but not defined in the mdns config. - // It will first copy the defaults into an empty object, then copy any real config over that. - var mdnsDefaults = { port: 5353, broadcast: '224.0.0.251', ttl: 300 }; - config.mdns = Object.assign({}, mdnsDefaults, config.mdns); + // Use Object.assign to copy any real config values over the default values so we can + // easily make sure all the fields we need exist . + var mdnsDefaults = { disabled: false, port: 5353, broadcast: '224.0.0.251', ttl: 300 }; + config.mdns = Object.assign(mdnsDefaults, config.mdns); - if (!config.tcp) { - config.tcp = {}; - } - if (!config.http) { - config.http = { modules: [{ name: 'proxy', domains: ['*'], port: 3000 }] }; - } - if (!config.tls) { - config.tls = {}; + function fillComponent(name, fillBind, fillDomains) { + if (!config[name]) { + config[name] = {}; + } + if (!Array.isArray(config[name].modules)) { + config[name].modules = []; + } + + 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); + if (!config.tls.acme && (args.email || args.agreeTos)) { config.tls.acme = {}; } @@ -175,14 +191,13 @@ function fillConfig(config, args) { config.tls.acme.approvedDomains = args.agreeTos.split(','); } if (args.email) { - config.email = args.email; config.tls.acme.email = args.email; } config.device = { hostname: require('os').hostname() }; config.tunnel = args.tunnel || config.tunnel; - if (Array.isArray(config.tcp.bind)) { + if (Array.isArray(config.tcp.bind) && config.tcp.bind.length) { return PromiseA.resolve(config); }