dist / n8nConfig.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.loadN8nConfig = loadN8nConfig;
const fs_1 = require("fs");
const path_1 = require("path");
const DEFAULT_CONFIG = {
api_url: "",
api_key: "",
api_version_path: "/api/v1",
};
let cachedConfig = null;
function loadN8nConfig(reload = false) {
if (cachedConfig !== null && !reload) {
return cachedConfig;
}
const configPath = (0, path_1.join)(__dirname, "..", "n8n-config.json");
if ((0, fs_1.existsSync)(configPath)) {
try {
const raw = (0, fs_1.readFileSync)(configPath, "utf-8");
const parsed = JSON.parse(raw);
cachedConfig = {
api_url: parsed.api_url ?? DEFAULT_CONFIG.api_url,
api_key: parsed.api_key ?? DEFAULT_CONFIG.api_key,
api_version_path: parsed.api_version_path ?? DEFAULT_CONFIG.api_version_path,
};
}
catch {
cachedConfig = { ...DEFAULT_CONFIG };
}
}
else {
cachedConfig = { ...DEFAULT_CONFIG };
}
return cachedConfig;
}