Skip to content

Commit

Permalink
#7162: Don't modify the original API URL when prepending BASE_PATH
Browse files Browse the repository at this point in the history
  • Loading branch information
thatmattlove committed Sep 7, 2021
1 parent 70cd096 commit c35563d
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 16 deletions.
2 changes: 1 addition & 1 deletion netbox/project-static/dist/config.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion netbox/project-static/dist/config.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion netbox/project-static/dist/jobs.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion netbox/project-static/dist/jobs.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion netbox/project-static/dist/lldp.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion netbox/project-static/dist/lldp.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion netbox/project-static/dist/netbox.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion netbox/project-static/dist/netbox.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions netbox/project-static/dist/status.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion netbox/project-static/dist/status.js.map

Large diffs are not rendered by default.

14 changes: 9 additions & 5 deletions netbox/project-static/src/util.ts
Expand Up @@ -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.
Expand Down

0 comments on commit c35563d

Please sign in to comment.