changed the default config

This commit is contained in:
tigerbot 2017-10-04 18:26:27 -06:00
parent cc6b34dd46
commit d04b750f87
1 changed files with 32 additions and 17 deletions

View File

@ -148,26 +148,42 @@ var tcpProm;
function fillConfig(config, args) { function fillConfig(config, args) {
config.debug = config.debug || args.debug; config.debug = config.debug || args.debug;
if (!config.dns) {
config.dns = { bind: [ 53 ], modules: [{ name: 'proxy', port: 3053 }] };
}
if (!config.ddns) { if (!config.ddns) {
config.ddns = { enabled: false }; config.ddns = { enabled: false };
} }
// Use Object.assign to add any properties needed but not defined in the mdns config. // Use Object.assign to copy any real config values over the default values so we can
// It will first copy the defaults into an empty object, then copy any real config over that. // easily make sure all the fields we need exist .
var mdnsDefaults = { port: 5353, broadcast: '224.0.0.251', ttl: 300 }; var mdnsDefaults = { disabled: false, port: 5353, broadcast: '224.0.0.251', ttl: 300 };
config.mdns = Object.assign({}, mdnsDefaults, config.mdns); config.mdns = Object.assign(mdnsDefaults, config.mdns);
if (!config.tcp) { function fillComponent(name, fillBind, fillDomains) {
config.tcp = {}; if (!config[name]) {
} config[name] = {};
if (!config.http) { }
config.http = { modules: [{ name: 'proxy', domains: ['*'], port: 3000 }] }; if (!Array.isArray(config[name].modules)) {
} config[name].modules = [];
if (!config.tls) { }
config.tls = {};
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)) { if (!config.tls.acme && (args.email || args.agreeTos)) {
config.tls.acme = {}; config.tls.acme = {};
} }
@ -175,14 +191,13 @@ function fillConfig(config, args) {
config.tls.acme.approvedDomains = args.agreeTos.split(','); config.tls.acme.approvedDomains = args.agreeTos.split(',');
} }
if (args.email) { if (args.email) {
config.email = args.email;
config.tls.acme.email = args.email; config.tls.acme.email = args.email;
} }
config.device = { hostname: require('os').hostname() }; config.device = { hostname: require('os').hostname() };
config.tunnel = args.tunnel || config.tunnel; 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); return PromiseA.resolve(config);
} }