Skip to content

Commit dadfa0c

Browse files
talvesbrianlmacdonald
authored andcommitted
Allow for un-captured route of config.yml (decaporg#1182)
1 parent d1bb7a1 commit dadfa0c

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

src/actions/config.js

+17-9
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,21 @@ function parseConfig(data) {
7575
return config;
7676
}
7777

78+
async function getConfig(file, isPreloaded) {
79+
const response = await fetch(file, { credentials: 'same-origin' });
80+
if (response.status !== 200) {
81+
if (isPreloaded) return parseConfig('');
82+
throw new Error(`Failed to load config.yml (${ response.status })`);
83+
}
84+
const contentType = response.headers.get('Content-Type') || 'Not-Found';
85+
const isYaml = contentType.indexOf('yaml') !== -1;
86+
if (!isYaml) {
87+
console.log(`Response for ${ file } was not yaml. (Content-Type: ${ contentType })`);
88+
if (isPreloaded) return parseConfig('');
89+
}
90+
return parseConfig(await response.text());
91+
}
92+
7893
export function configLoaded(config) {
7994
return {
8095
type: CONFIG_SUCCESS,
@@ -115,19 +130,12 @@ export function loadConfig() {
115130

116131
try {
117132
const preloadedConfig = getState().config;
118-
const response = await fetch('config.yml', { credentials: 'same-origin' })
119-
const requestSuccess = response.status === 200;
120-
121-
if (!preloadedConfig && !requestSuccess) {
122-
throw new Error(`Failed to load config.yml (${ response.status })`);
123-
}
124-
125-
const loadedConfig = parseConfig(requestSuccess ? await response.text() : '');
133+
const loadedConfig = await getConfig('config.yml', preloadedConfig && preloadedConfig.size > 1);
126134

127135
/**
128136
* Merge any existing configuration so the result can be validated.
129137
*/
130-
const mergedConfig = mergePreloadedConfig(preloadedConfig, loadedConfig)
138+
const mergedConfig = mergePreloadedConfig(preloadedConfig, loadedConfig);
131139
const config = flow(validateConfig, applyDefaults)(mergedConfig);
132140

133141
dispatch(configDidLoad(config));

0 commit comments

Comments
 (0)