rspack-plugin-cloudflare 0.5.7 → 0.5.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -5000,17 +5000,27 @@ const staticRedirectsMatcher = (configuration, host, pathname) => {
|
|
|
5000
5000
|
}
|
|
5001
5001
|
return withHostMatch || withoutHostMatch;
|
|
5002
5002
|
};
|
|
5003
|
-
const generateRedirectsMatcher = (configuration) => generateRulesMatcher(configuration.redirects.version === 1 ? configuration.redirects.rules : {}, ({ status, to }, replacements) => {
|
|
5004
|
-
|
|
5005
|
-
|
|
5006
|
-
|
|
5007
|
-
|
|
5008
|
-
|
|
5009
|
-
|
|
5010
|
-
|
|
5011
|
-
|
|
5012
|
-
|
|
5013
|
-
|
|
5003
|
+
const generateRedirectsMatcher = (configuration) => generateRulesMatcher(configuration.redirects.version === 1 ? configuration.redirects.rules : {}, ({ status, to }, replacements) => ({
|
|
5004
|
+
status,
|
|
5005
|
+
to: normalizeRedirectTarget(to, replacements)
|
|
5006
|
+
}));
|
|
5007
|
+
/**
|
|
5008
|
+
* Replace redirect placeholders and normalize relative pathnames without changing
|
|
5009
|
+
* query values, fragments or explicitly configured external URLs.
|
|
5010
|
+
*
|
|
5011
|
+
* @param value The configured redirect target before placeholder replacement.
|
|
5012
|
+
* @param replacements Placeholder values captured from the request.
|
|
5013
|
+
* @returns A substituted target with repeated relative pathname separators collapsed.
|
|
5014
|
+
*/
|
|
5015
|
+
function normalizeRedirectTarget(value, replacements) {
|
|
5016
|
+
const isExternal = /^(?:\w+:\/\/|\/\/[^/\\\s?#])/.test(value.trim());
|
|
5017
|
+
const target = replacer(value, replacements).trim();
|
|
5018
|
+
if (isExternal) return target;
|
|
5019
|
+
const suffixStart = target.search(/[?#]/);
|
|
5020
|
+
const pathname = suffixStart === -1 ? target : target.slice(0, suffixStart);
|
|
5021
|
+
const suffix = suffixStart === -1 ? "" : target.slice(suffixStart);
|
|
5022
|
+
return pathname.replace(/[/\\]+/g, "/") + suffix;
|
|
5023
|
+
}
|
|
5014
5024
|
// workers-sdk/packages/workers-shared/asset-worker/src/utils/headers.ts
|
|
5015
5025
|
/**
|
|
5016
5026
|
* Returns a Headers object that contains additional headers (to those
|