Skip to content

Commit

Permalink
fix(cli): Forward slashes problem when serving from e.g. S3 (#1800)
Browse files Browse the repository at this point in the history
somehow the urls generated are like `https://domain//pwa/fb3c65966433393af9889753675af9c9.json`
this will fail when serving those from an S3. so we make sure we normalize them before request
  • Loading branch information
digitalkaoz authored Feb 1, 2022
1 parent db569f7 commit 5b605bf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/cli/src/extensions/plugins-extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ module.exports = (toolbox: GluegunToolbox) => {
const url =
config.indexOf(endpoint) >= 0
? config
: `${toolbox.normalizeBaseUrl(
: toolbox.normalizeForwardSlashes(`${toolbox.normalizeBaseUrl(
toolbox.inputParameters.shopwareEndpoint
)}/${config}`;
)}/${config}`);
const pluginsConfigResponse = await axios.get(url);
return pluginsConfigResponse.data;
};
Expand All @@ -74,9 +74,9 @@ module.exports = (toolbox: GluegunToolbox) => {
const fileUrl =
asset.indexOf(endpoint) >= 0
? asset
: `${toolbox.normalizeBaseUrl(
: toolbox.normalizeForwardSlashes(`${toolbox.normalizeBaseUrl(
toolbox.inputParameters.shopwareEndpoint
)}/${asset}`;
)}/${asset}`);

const request = require("request");
const loadFile = function () {
Expand Down
10 changes: 10 additions & 0 deletions packages/cli/src/extensions/shopware-pwa-extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,16 @@ module.exports = (toolbox: GluegunToolbox) => {
return toolbox.strings.trimEnd(baseUrl, "/");
};

/**
* Removes forward slashes from URLs
*
* @param { string } baseUrl
* @returns { string }
*/
toolbox.normalizeForwardSlashes = (baseUrl: string): string => {
return baseUrl.replace(/([^:]\/)\/+/g, "$1")
};

/**
* Checks if provided API has PWA extension installed
* by making a request to the page resolver
Expand Down

0 comments on commit 5b605bf

Please sign in to comment.