mirror of
https://github.com/strapi/strapi.git
synced 2025-11-10 23:29:33 +00:00
fix: fallback to window.location.href if backendURL is not defined (#17982)
Co-authored-by: Jamie Howard <48524071+jhoward1994@users.noreply.github.com>
This commit is contained in:
parent
ef5f997c57
commit
ef41a56cf1
@ -10,7 +10,7 @@ const appendSearchParamsToUrl = ({ url, params }) => {
|
|||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
const urlObj = new URL(url, window.strapi.backendURL);
|
const urlObj = new URL(url, window.strapi.backendURL ?? window.location.origin);
|
||||||
|
|
||||||
Object.entries(params).forEach(([key, value]) => {
|
Object.entries(params).forEach(([key, value]) => {
|
||||||
if (value !== undefined) {
|
if (value !== undefined) {
|
||||||
|
|||||||
@ -102,5 +102,18 @@ describe('appendSearchParamsToUrl', () => {
|
|||||||
`"https://appending-search-params.com/uploads/image.jpg?param1=example1¶m2=example2"`
|
`"https://appending-search-params.com/uploads/image.jpg?param1=example1¶m2=example2"`
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("if there's no window.strapi.backendURL, it uses window.location.origin", () => {
|
||||||
|
const oldBackendURL = window.strapi.backendURL;
|
||||||
|
window.strapi.backendURL = undefined;
|
||||||
|
|
||||||
|
expect(
|
||||||
|
appendSearchParamsToUrl({ url, params: { updatedAt: updateTime } })
|
||||||
|
).toMatchInlineSnapshot(
|
||||||
|
`"http://localhost:1337/uploads/image.jpg?updatedAt=2023-07-19T03%3A00%3A00.000Z"`
|
||||||
|
);
|
||||||
|
|
||||||
|
window.strapi.backendURL = oldBackendURL;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user