#7162: Don't modify the original API URL when prepending BASE_PATH

This commit is contained in:
thatmattlove 2021-09-07 14:08:02 -07:00
parent 70cd0969e4
commit c35563d82f
11 changed files with 9 additions and 5 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -163,17 +163,21 @@ function buildUrl(destination: string): string {
// If the `origin` exists in the API path (as in the case of paginated responses), remove it.
const origin = new RegExp(window.location.origin, 'g');
let path = pathname.replaceAll(origin, '');
let path = pathname
.replaceAll(origin, '')
.split('/')
.filter(p => p);
const basePath = getBasePath();
// If the `BASE_PATH` already exists in the URL, remove it.
if (basePath !== '' && path.includes(basePath)) {
path = path.replaceAll(basePath, '');
// If the `BASE_PATH` already exists in the URL, and it is the first element, remove it.
if (basePath !== '' && path[0].includes(basePath)) {
const [_, ...appPath] = path;
path = ['', ...appPath];
}
// Combine `BASE_PATH` with this request's path, removing _all_ slashes.
let combined = [...basePath.split('/'), ...path.split('/')].filter(p => p);
let combined = [...basePath.split('/'), ...path].filter(p => p);
if (combined[0] !== '/') {
// Ensure the URL has a leading slash.