2020-02-10 12:45:15 +01:00
|
|
|
import { getConfig } from 'app/core/config';
|
2018-02-01 16:30:48 +01:00
|
|
|
|
2019-02-04 18:24:56 +01:00
|
|
|
export const stripBaseFromUrl = (url: string): string => {
|
2020-02-10 12:45:15 +01:00
|
|
|
const appSubUrl = getConfig().appSubUrl;
|
2018-02-01 16:30:48 +01:00
|
|
|
const stripExtraChars = appSubUrl.endsWith('/') ? 1 : 0;
|
|
|
|
|
const urlWithoutBase =
|
|
|
|
|
url.length > 0 && url.indexOf(appSubUrl) === 0 ? url.slice(appSubUrl.length - stripExtraChars) : url;
|
|
|
|
|
|
|
|
|
|
return urlWithoutBase;
|
|
|
|
|
};
|
|
|
|
|
|
2020-02-10 12:45:15 +01:00
|
|
|
export const assureBaseUrl = (url: string) => {
|
|
|
|
|
if (url.startsWith('/')) {
|
|
|
|
|
return `${getConfig().appSubUrl}${stripBaseFromUrl(url)}`;
|
|
|
|
|
}
|
|
|
|
|
return url;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default { stripBaseFromUrl, assureBaseUrl };
|