Skip to content

Commit

Permalink
refactor: extract host to a variable
Browse files Browse the repository at this point in the history
  • Loading branch information
fpdrozd committed Mar 27, 2023
1 parent a7f472b commit 2bb9363
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions packages/api-client/src/api/serializers/product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,17 @@ const addHostToImage = (image, config: ApiConfig) => ({
...image,
attributes: {
...image.attributes,
styles: image.attributes?.styles ? image.attributes.styles.map((style) => ({
width: style.width,
height: style.height,
url: `${style.url.includes('http') ? '' : (config.assetsUrl || config.backendUrl)}${style.url}`
})) : []
styles: image.attributes?.styles ? image.attributes.styles.map((style) => {
const host = style.url.startsWith('http://') || style.url.startsWith('https://')
? ''
: (config.assetsUrl || config.backendUrl);

return {
width: style.width,
height: style.height,
url: `${host}${style.url}`
};
}) : []
}
});

Expand Down

0 comments on commit 2bb9363

Please sign in to comment.