LoRaWAN-Signal-Mapping/server/bootstrap/settings.mjs

30 lines
806 B
JavaScript
Raw Normal View History

"use strict";
import path from 'path';
import fs from 'fs';
import toml from '@iarna/toml';
import apply_settings from '../Helpers/apply_settings.mjs';
const root_dir = path.dirname(process.argv[1]);
let filename_default = path.resolve(root_dir, "./settings.default.toml"),
filename_custom = path.resolve(root_dir, "../settings.toml");
if(!fs.existsSync(filename_custom)) {
fs.writeFileSync(
filename_custom,
`# Custom settings file. This file overrides server/settings.default.toml - refer there for examples of settings you can override.\n\n`, {
mode: 0o600
}
);
}
let settings = toml.parse(fs.readFileSync(filename_default, "utf-8")),
settings_override = toml.parse(fs.readFileSync(filename_custom, "utf-8"));
apply_settings(settings, settings_override);
export default settings;