All files / platform/app/src loadDynamicConfig.js

27.27% Statements 3/11
0% Branches 0/4
100% Functions 1/1
27.27% Lines 3/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24  34x     34x                                 34x    
export default async config => {
  const useDynamicConfig = config.dangerouslyUseDynamicConfig;
 
  // Check if dangerouslyUseDynamicConfig enabled
  Iif (useDynamicConfig?.enabled) {
    // If enabled then get configUrl query-string
    let query = new URLSearchParams(window.location.search);
    let configUrl = query.get('configUrl');
 
    Iif (configUrl) {
      // validate regex
      const regex = useDynamicConfig.regex;
 
      if (configUrl.match(regex)) {
        const response = await fetch(configUrl);
        return response.json();
      } else {
        return null;
      }
    }
  }
  return null;
};