mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-09-16 17:40:46 -04:00
23 lines
617 B
JavaScript
23 lines
617 B
JavaScript
// Config Loader Helper
|
|
// Purpose: Loads and validates YAML server configuration from configured paths. Scope: Provides normalized config access with sane defaults and cache behavior.
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const yaml = require('js-yaml');
|
|
|
|
const CONFIG_PATH = process.env.SERVER_CONFIG || path.join(__dirname, '..', '..', 'config.yaml');
|
|
|
|
let cachedConfig;
|
|
|
|
function loadConfig() {
|
|
if (cachedConfig) {
|
|
return cachedConfig;
|
|
}
|
|
const file = fs.readFileSync(CONFIG_PATH, 'utf8');
|
|
cachedConfig = yaml.load(file);
|
|
return cachedConfig;
|
|
}
|
|
|
|
module.exports = {
|
|
loadConfig,
|
|
};
|