All files / utils getConfig.js

0% Statements 0/19
0% Branches 0/12
0% Functions 0/4
0% Lines 0/17
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31                                                             
let configFile = null;
 
const getConfig = () =>
  new Promise((resolve, reject) => {
    if (configFile) {
      resolve(configFile);
    } else if (window && window.parent) {
      const url = window.parent.location;
      const location = `${url.protocol}//${url.hostname}:${url.port}/storybook-config.json`;
 
      fetch(location).then(response => {
        if (response.ok) {
          response.json().then(data => {
            if (data && data.storybook) {
              configFile = data.storybook;
              resolve(configFile);
            } else {
              reject('Invalid config');
            }
          });
        } else {
          reject('Error getting config');
        }
      });
    } else {
      reject('Window not found');
    }
  });
 
export default getConfig;