diff --git a/src/utils.js b/src/utils.js index fa6f30337..925e780d3 100644 --- a/src/utils.js +++ b/src/utils.js @@ -95,12 +95,31 @@ export function parseArrayOrObjectValues(obj) { return result; } +/** + * Create a correct inner path depend on config PUBLIC_PATH. + * @param {string} checkPath - the internal route path that is validated + * @returns {string} - the correct internal route path + */ +export const createCorrectInternalRoute = (checkPath) => { + let basePath = getPath(getConfig().PUBLIC_PATH); + + if (basePath.endsWith('/')) { + basePath = basePath.slice(0, -1); + } + + if (!checkPath.startsWith(basePath)) { + return `${basePath}${checkPath}`; + } + + return checkPath; +}; + export function getPagePath(courseId, isMfePageEnabled, urlParameter) { if (isMfePageEnabled === 'true') { if (urlParameter === 'tabs') { - return `${getConfig().BASE_URL}/course/${courseId}/pages-and-resources`; + return createCorrectInternalRoute(`/course/${courseId}/pages-and-resources`); } - return `${getConfig().BASE_URL}/course/${courseId}/${urlParameter}`; + return createCorrectInternalRoute(`/course/${courseId}/${urlParameter}`); } return `${getConfig().STUDIO_BASE_URL}/${urlParameter}/${courseId}`; } @@ -268,22 +287,3 @@ export const getFileSizeToClosestByte = (fileSize) => { const fileSizeFixedDecimal = Number.parseFloat(size).toFixed(2); return `${fileSizeFixedDecimal} ${units[divides]}`; }; - -/** - * Create a correct inner path depend on config PUBLIC_PATH. - * @param {string} checkPath - the internal route path that is validated - * @returns {string} - the correct internal route path - */ -export const createCorrectInternalRoute = (checkPath) => { - let basePath = getPath(getConfig().PUBLIC_PATH); - - if (basePath.endsWith('/')) { - basePath = basePath.slice(0, -1); - } - - if (!checkPath.startsWith(basePath)) { - return `${basePath}${checkPath}`; - } - - return checkPath; -};