MCPcopy Create free account
hub / github.com/bigcommerce/stencil-cli / normalizeRedirectUrl

Function normalizeRedirectUrl

server/lib/utils.js:20–32  ·  view source on GitHub ↗

* Strip domain from redirectUrl if it matches the current storeUrl, if not, leave it. * * @param {string} redirectUrl * @param {{ normalStoreUrl, storeUrl}} config * @returns {string}

(redirectUrl, config)

Source from the content-addressed store, hash-verified

18 * @returns {string}
19 */
20function normalizeRedirectUrl(redirectUrl, config) {
21 if (!redirectUrl || !redirectUrl.startsWith('http')) {
22 return redirectUrl; // already stripped, skip
23 }
24 const storeHost = new URL(config.normalStoreUrl).host;
25 const secureStoreHost = new URL(config.storeUrl).host;
26 const redirectUrlObj = new URL(redirectUrl);
27 if (redirectUrlObj.host === storeHost || redirectUrlObj.host === secureStoreHost) {
28 // Need to strip
29 return redirectUrlObj.pathname + redirectUrlObj.search + redirectUrlObj.hash;
30 }
31 return redirectUrl; // Different host, shouldn't strip
32}
33/**
34 * Convert a number to uuid
35 *

Callers 2

utils.spec.jsFile · 0.90
renderer.module.jsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected