mirror of
https://github.com/strapi/strapi.git
synced 2025-11-16 10:07:55 +00:00
Merge pull request #18028 from strapi/fix/backend-url-can-be-empty-string
This commit is contained in:
commit
e22b016617
@ -8,7 +8,13 @@ import plugins from './plugins';
|
|||||||
import appReducers from './reducers';
|
import appReducers from './reducers';
|
||||||
|
|
||||||
window.strapi = {
|
window.strapi = {
|
||||||
backendURL: process.env.STRAPI_ADMIN_BACKEND_URL,
|
/**
|
||||||
|
* This ENV variable is passed from the strapi instance, by default no url is set
|
||||||
|
* in the config and therefore the instance returns you an empty string so URLs are relative.
|
||||||
|
*
|
||||||
|
* To ensure that the backendURL is always set, we use the window.location.origin as a fallback.
|
||||||
|
*/
|
||||||
|
backendURL: process.env.STRAPI_ADMIN_BACKEND_URL || window.location.origin,
|
||||||
isEE: false,
|
isEE: false,
|
||||||
telemetryDisabled: process.env.STRAPI_TELEMETRY_DISABLED ?? false,
|
telemetryDisabled: process.env.STRAPI_TELEMETRY_DISABLED ?? false,
|
||||||
features: {
|
features: {
|
||||||
|
|||||||
@ -10,7 +10,7 @@ const appendSearchParamsToUrl = ({ url, params }) => {
|
|||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
const urlObj = new URL(url, window.strapi.backendURL ?? window.location.origin);
|
const urlObj = new URL(url, window.strapi.backendURL);
|
||||||
|
|
||||||
Object.entries(params).forEach(([key, value]) => {
|
Object.entries(params).forEach(([key, value]) => {
|
||||||
if (value !== undefined) {
|
if (value !== undefined) {
|
||||||
|
|||||||
@ -102,18 +102,5 @@ 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