All files / platform/core/src/utils absoluteUrl.js

9.09% Statements 1/11
0% Branches 0/3
0% Functions 0/1
9.09% Lines 1/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 2334x                                            
const absoluteUrl = path => {
  let absolutePath = '/';
 
  Iif (!path) {
    return absolutePath;
  }
 
  // TODO: Find another way to get root url
  const absoluteUrl = window.location.origin;
  const absoluteUrlParts = absoluteUrl.split('/');
 
  if (absoluteUrlParts.length > 4) {
    const rootUrlPrefixIndex = absoluteUrl.indexOf(absoluteUrlParts[3]);
    absolutePath += absoluteUrl.substring(rootUrlPrefixIndex) + path;
  } else {
    absolutePath += path;
  }
 
  return absolutePath.replace(/\/\/+/g, '/');
};
 
export default absoluteUrl;