let configFile = null;
const getConfig = (filename = 'storybook-config.json') => (
new Promise((resolve, reject) => {
if (configFile) {
resolve(configFile);
} else if (window && window.parent) {
console.log('********************' ,filename)
const url = window.parent.location;
const location = `${url.protocol}//${url.hostname}:${url.port}/${filename}`;
fetch(location).then((response) => {
if (response.ok) {
response.json().then((data) => {
if (data && data.storybook && data.storybook.versions) {
configFile = data.storybook.versions;
resolve(configFile);
} else {
reject('Invalid config: ', response);
}
});
} else {
reject('Error in reponse: ', response);
}
}).catch((err) => {
reject('Error getting config: ', err);
});
} else {
reject('Window not found');
}
})
);
export default getConfig;
|