homebridge-config-ui-x
Version:
A web based management, configuration and control platform for Homebridge
52 lines • 2.39 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const os = require("os");
const path = require("path");
const fs = require("fs-extra");
function getStartupConfig() {
return __awaiter(this, void 0, void 0, function* () {
const configPath = process.env.UIX_CONFIG_PATH || path.resolve(os.homedir(), '.homebridge/config.json');
const homebridgeConfig = yield fs.readJSON(configPath);
const ui = Array.isArray(homebridgeConfig.platforms) ? homebridgeConfig.platforms.find(x => x.platform === 'config') : undefined;
const config = {};
const ipv6 = Object.entries(os.networkInterfaces()).filter(([net, addresses]) => {
return addresses.find(x => x.family === 'IPv6');
}).length;
config.host = ipv6 ? '::' : '0.0.0.0';
if (!ui) {
return config;
}
if (ui.host) {
config.host = ui.host;
}
if (ui.ssl && ((ui.ssl.key && ui.ssl.cert) || ui.ssl.pfx)) {
config.httpsOptions = {
key: ui.ssl.key ? yield fs.readFile(ui.ssl.key) : undefined,
cert: ui.ssl.cert ? yield fs.readFile(ui.ssl.cert) : undefined,
pfx: ui.ssl.pfx ? yield fs.readFile(ui.ssl.pfx) : undefined,
passphrase: ui.ssl.passphrase,
};
}
if (ui.proxyHost) {
config.cspWsOveride = `wss://${ui.proxyHost} ws://${ui.proxyHost}`;
}
if (ui.debug) {
config.debug = true;
}
else {
config.debug = false;
}
return config;
});
}
exports.getStartupConfig = getStartupConfig;
//# sourceMappingURL=config.startup.js.map