generated from Seekra/repository-template
add settings configuration parser #78
@@ -17,21 +17,16 @@ limitations under the License.
|
|||||||
import { validateSettingsConfig } from './settingsValidator.js';
|
import { validateSettingsConfig } from './settingsValidator.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads and parses the settings configuration from a JSON file.
|
* Loads and parses the settings configuration via dynamic import.
|
||||||
* @param {string} [url='/settings.json']
|
|
||||||
* @returns {Promise<import('../types/settingsConfig').SettingsConfig>}
|
* @returns {Promise<import('../types/settingsConfig').SettingsConfig>}
|
||||||
*/
|
*/
|
||||||
export async function loadSettingsConfig(url = '/settings.json') {
|
export async function loadSettingsConfig() {
|
||||||
let raw;
|
let raw;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(url);
|
raw = (await import('../settings.json')).default;
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error(`HTTP ${response.status}`);
|
|
||||||
}
|
|
||||||
raw = await response.json();
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new Error(`[settings] Failed to load config from "${url}": ${e.message}`);
|
throw new Error(`[settings] Failed to load settings.json: ${e.message}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = validateSettingsConfig(raw);
|
const result = validateSettingsConfig(raw);
|
||||||
|
|||||||
Reference in New Issue
Block a user