UNPKG

exthos

Version:

stream processing in nodejs using the power of golang

58 lines 1.99 kB
import { readFileSync } from "fs"; import merge from "lodash.merge"; import debug from "../utils/debug.js"; import { nanojq } from "../utils/nanojq.js"; import { formatErrorForEvent } from "../utils/utils.js"; import config from "./config.default.js"; Object.defineProperty(config, "debugLog", { enumerable: false, writable: false, value: debug.extend("config"), }); config["refresh"] = function () { let config = this; try { let configFile = readFileSync("./exthos.config.json"); merge(config, JSON.parse(configFile.toString())); config.debugLog("successfully merged ./exthos.config.json"); } catch (e) { if (e.code === "ENOENT") { config.debugLog("./exthos.config.json not present"); } else { config.debugLog("failed to merge ./exthos.config.json", { error: formatErrorForEvent(e), }); } } try { let toMerge = {}; Object.keys(process.env) .filter((k) => k.startsWith("EXTHOS_")) .forEach((k) => { let toMergeKey = k.replace(/^EXTHOS_/, ""); let toMergeValue = process.env[k]; if (["true", "false"].includes(process.env[k])) { toMergeValue = toMergeValue === "true"; } else if (parseFloat(toMergeValue) !== NaN) { toMergeValue = parseFloat(toMergeValue); } toMerge = nanojq.set(toMerge, toMergeKey, toMergeValue); }); merge(config, toMerge); config.debugLog("successfully merged env variables EXTHOS_*"); } catch (e) { config.debugLog("failed to merge env variables EXTHOS_*", { error: formatErrorForEvent(e), }); } }; config.refresh(); let engineExtraConfig = config.engineExtraConfig; let engineConfig = config.engineConfig; export { engineExtraConfig, engineConfig }; export default config; //# sourceMappingURL=config.js.map