@next/routing 16.2.0-canary.7 → 16.2.0-canary.71
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.
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{"use strict";var e={};(()=>{e.d=(t,n)=>{for(var a in n){if(e.o(n,a)&&!e.o(t,a)){Object.defineProperty(t,a,{enumerable:true,get:n[a]})}}}})();(()=>{e.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t)})();(()=>{e.r=e=>{if(typeof Symbol!=="undefined"&&Symbol.toStringTag){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})}Object.defineProperty(e,"__esModule",{value:true})}})();if(typeof e!=="undefined")e.ab=__dirname+"/";var t={};e.r(t);e.d(t,{detectDomainLocale:()=>detectDomainLocale,detectLocale:()=>detectLocale,getAcceptLanguageLocale:()=>getAcceptLanguageLocale,getCookieLocale:()=>getCookieLocale,normalizeLocalePath:()=>normalizeLocalePath,resolveRoutes:()=>resolveRoutes,responseToMiddlewareResult:()=>responseToMiddlewareResult});function matchesCondition(e,t){if(e===undefined){return{matched:false}}if(t===undefined){return{matched:true,capturedValue:e}}try{const n=new RegExp(t);const a=e.match(n);if(a){return{matched:true,capturedValue:a[0]}}}catch(e){}if(e===t){return{matched:true,capturedValue:e}}return{matched:false}}function getConditionValue(e,t,n){switch(e.type){case"header":return n.get(e.key)||undefined;case"cookie":{const t=n.get("cookie");if(!t)return undefined;const a=t.split(";").reduce(((e,t)=>{const[n,...a]=t.trim().split("=");if(n){e[n]=a.join("=")}return e}),{});return a[e.key]}case"query":return t.searchParams.get(e.key)||undefined;case"host":return t.hostname;default:return""}}function normalizeCaptureKey(e){return e.replace(/[^a-zA-Z]/g,"")}function checkHasConditions(e,t,n){if(!e||e.length===0){return{matched:true,captures:{}}}const a={};for(const r of e){const e=getConditionValue(r,t,n);const s=matchesCondition(e,r.value);if(!s.matched){return{matched:false,captures:{}}}if(s.capturedValue!==undefined&&r.type!=="host"){const e=normalizeCaptureKey(r.key);a[e]=s.capturedValue}}return{matched:true,captures:a}}function checkMissingConditions(e,t,n){if(!e||e.length===0){return true}for(const a of e){const e=getConditionValue(a,t,n);const r=matchesCondition(e,a.value);if(r.matched){return false}}return true}function replaceDestination(e,t,n){let a=e;if(t){for(let e=1;e<t.length;e++){const n=t[e];if(n!==undefined){a=a.replace(new RegExp(`\\$${e}`,"g"),n)}}if(t.groups){for(const[e,n]of Object.entries(t.groups)){if(n!==undefined){a=a.replace(new RegExp(`\\$${e}`,"g"),n)}}}}for(const[e,t]of Object.entries(n)){a=a.replace(new RegExp(`\\$${e}`,"g"),t)}return a}function isExternalDestination(e){return e.startsWith("http://")||e.startsWith("https://")}function applyDestination(e,t){if(isExternalDestination(t)){return new URL(t)}const n=new URL(e.toString());const[a,r]=t.split("?");n.pathname=a;if(r){const e=new URLSearchParams(r);for(const[t,a]of e.entries()){n.searchParams.set(t,a)}}return n}function isRedirectStatus(e){if(!e)return false;return e>=300&&e<400}function hasRedirectHeaders(e){const t=Object.keys(e).map((e=>e.toLowerCase()));return t.includes("location")||t.includes("refresh")}function normalizeNextDataUrl(e,t,n){const a=new URL(e.toString());let r=a.pathname;const s=`${t}/_next/data/${n}/`;if(r.startsWith(s)){let e=r.slice(s.length);if(e.endsWith(".json")){e=e.slice(0,-5)}r=t?`${t}/${e}`:`/${e}`;a.pathname=r}return a}function denormalizeNextDataUrl(e,t,n){const a=new URL(e.toString());let r=a.pathname;const s=`${t}/_next/data/${n}/`;if(!r.startsWith(s)){let e=r;if(t&&r.startsWith(t)){e=r.slice(t.length)}r=`${t}/_next/data/${n}${e}.json`;a.pathname=r}return a}function detectDomainLocale(e,t,n){if(!e)return undefined;const a=t?.toLowerCase();const r=n?.toLowerCase();for(const t of e){const e=t.domain.split(":",1)[0].toLowerCase();if(a===e||r===t.defaultLocale.toLowerCase()||t.locales?.some((e=>e.toLowerCase()===r))){return t}}return undefined}function normalizeLocalePath(e,t){if(!t||t.length===0){return{pathname:e}}const n=e.split("/",2);if(!n[1]){return{pathname:e}}const a=n[1].toLowerCase();const r=t.map((e=>e.toLowerCase()));const s=r.indexOf(a);if(s<0){return{pathname:e}}const o=t[s];const i=e.slice(o.length+1)||"/";return{pathname:i,detectedLocale:o}}function getAcceptLanguageLocale(e,t){if(!e||!t.length){return undefined}try{const n=e.split(",").map((e=>{const t=e.trim().split(";");const n=t[0];let a=1;if(t[1]){const e=t[1].match(/q=([0-9.]+)/);if(e&&e[1]){a=parseFloat(e[1])}}return{locale:n,quality:a}})).filter((e=>e.quality>0)).sort(((e,t)=>t.quality-e.quality));const a=new Map;for(const e of t){a.set(e.toLowerCase(),e)}for(const{locale:e}of n){const t=e.toLowerCase();if(a.has(t)){return a.get(t)}}for(const{locale:e}of n){const t=e.toLowerCase().split("-")[0];if(a.has(t)){return a.get(t)}for(const[e,n]of a){if(e.startsWith(t+"-")){return n}}}return undefined}catch(e){return undefined}}function getCookieLocale(e,t){if(!e||!t.length){return undefined}try{const n=e.split(";").reduce(((e,t)=>{const[n,...a]=t.trim().split("=");if(n&&a.length>0){e[n]=decodeURIComponent(a.join("="))}return e}),{});const a=n.NEXT_LOCALE?.toLowerCase();if(!a){return undefined}return t.find((e=>e.toLowerCase()===a))}catch(e){return undefined}}function detectLocale(e){const{pathname:t,hostname:n,cookieHeader:a,acceptLanguageHeader:r,i18n:s}=e;const o=normalizeLocalePath(t,s.locales);if(o.detectedLocale){return{locale:o.detectedLocale,pathnameWithoutLocale:o.pathname,localeInPath:true}}if(s.localeDetection===false){const e=detectDomainLocale(s.domains,n);return{locale:e?.defaultLocale||s.defaultLocale,pathnameWithoutLocale:t,localeInPath:false}}const i=getCookieLocale(a,s.locales);if(i){return{locale:i,pathnameWithoutLocale:t,localeInPath:false}}const c=getAcceptLanguageLocale(r||"",s.locales);if(c){return{locale:c,pathnameWithoutLocale:t,localeInPath:false}}const d=detectDomainLocale(s.domains,n);if(d){return{locale:d.defaultLocale,pathnameWithoutLocale:t,localeInPath:false}}return{locale:s.defaultLocale,pathnameWithoutLocale:t,localeInPath:false}}function matchRoute(e,t,n){const a=new RegExp(e.sourceRegex);const r=t.pathname.match(a);if(!r){return{matched:false}}const s=checkHasConditions(e.has,t,n);if(!s.matched){return{matched:false}}const o=checkMissingConditions(e.missing,t,n);if(!o){return{matched:false}}const i=e.destination?replaceDestination(e.destination,r,s.captures):undefined;return{matched:true,destination:i,regexMatches:r,hasCaptures:s.captures}}function processRoutes(e,t,n,a){let r=t;let s;for(const t of e){const e=matchRoute(t,r,n);if(e.matched){if(t.headers){for(const[e,a]of Object.entries(t.headers)){n.set(e,a)}}if(t.status){s=t.status}if(e.destination){if(isRedirectStatus(t.status)&&t.headers&&hasRedirectHeaders(t.headers)){const n=isExternalDestination(e.destination)?new URL(e.destination):applyDestination(r,e.destination);return{url:r,redirect:{url:n,status:t.status},stopped:true,status:s}}if(isExternalDestination(e.destination)){return{url:r,externalRewrite:new URL(e.destination),stopped:true,status:s}}r=applyDestination(r,e.destination);if(r.origin!==a){return{url:r,externalRewrite:r,stopped:true,status:s}}}}}return{url:r,stopped:false,status:s}}function matchesPathname(e,t){for(const n of t){if(e===n){return n}}return undefined}function matchDynamicRoute(e,t){const n=new RegExp(t.sourceRegex);const a=e.match(n);if(!a){return{matched:false}}const r={};for(let e=1;e<a.length;e++){if(a[e]!==undefined){r[String(e)]=a[e]}}if(a.groups){Object.assign(r,a.groups)}return{matched:true,params:r}}function applyOnMatchHeaders(e,t){const n=new Headers(t);for(const t of e){if(t.headers){for(const[e,a]of Object.entries(t.headers)){n.set(e,a)}}}return n}function checkDynamicRoutes(e,t,n,a,r,s,o,i,c){let d=t;if(c&&i){d=denormalizeNextDataUrl(t,s,o)}for(const t of e){const e=matchDynamicRoute(d.pathname,t);if(e.matched){const s=checkHasConditions(t.has,d,a);const o=checkMissingConditions(t.missing,d,a);if(s.matched&&o){const t=matchesPathname(d.pathname,n);if(t){const n=applyOnMatchHeaders(r,a);return{matched:true,result:{matchedPathname:t,routeMatches:e.params,resolvedHeaders:n},resetUrl:d}}}}}return{matched:false}}async function resolveRoutes(e){const{url:t,basePath:n,requestBody:a,headers:r,pathnames:s,routes:o,invokeMiddleware:i,buildId:c,i18n:d}=e;const{shouldNormalizeNextData:l}=o;let u=new URL(t.toString());let f=new Headers(r);let h;const m=t.origin;let p=false;if(l){const e=`${n}/_next/data/${c}/`;p=t.pathname.startsWith(e);if(p){u=normalizeNextDataUrl(u,n,c)}}if(d&&!p){const e=u.pathname.startsWith(n)?u.pathname.slice(n.length)||"/":u.pathname;if(!e.startsWith("/_next/")){const t=u.hostname;const a=f.get("cookie")||undefined;const r=f.get("accept-language")||undefined;const s=normalizeLocalePath(e,d.locales);const o=!!s.detectedLocale;const i=detectDomainLocale(d.domains,t);const c=i?.defaultLocale||d.defaultLocale;let l=s.detectedLocale||c;if(d.localeDetection!==false&&!o){const s=detectLocale({pathname:e,hostname:t,cookieHeader:a,acceptLanguageHeader:r,i18n:d});l=s.locale;if(l!==c){const a=detectDomainLocale(d.domains,undefined,l);if(a&&a.domain!==t){const t=a.http?"http":"https";const r=l===a.defaultLocale?"":`/${l}`;const s=new URL(`${t}://${a.domain}${n}${r}${e}${u.search}`);return{redirect:{url:s,status:307},resolvedHeaders:f}}if(!a||a&&a.domain===t){const t=new URL(u.toString());t.pathname=`${n}/${l}${e}`;return{redirect:{url:t,status:307},resolvedHeaders:f}}}}if(!o){const t=l||i?.defaultLocale||d.defaultLocale;u.pathname=`${n}/${t}${e}`}}}const g=processRoutes(o.beforeMiddleware,u,f,m);if(g.status){h=g.status}if(g.redirect){return{redirect:g.redirect,resolvedHeaders:f,status:h}}if(g.externalRewrite){return{externalRewrite:g.externalRewrite,resolvedHeaders:f,status:h}}u=g.url;if(p&&l){u=denormalizeNextDataUrl(u,n,c)}const w=await i({url:u,headers:f,requestBody:a});if(w.bodySent){return{middlewareResponded:true}}if(w.requestHeaders){f=new Headers(w.requestHeaders)}if(w.redirect){f.set("Location",w.redirect.url.toString());return{resolvedHeaders:f,status:w.redirect.status}}if(w.rewrite){u=w.rewrite;if(u.origin!==m){return{externalRewrite:u,resolvedHeaders:f,status:h}}}if(p&&l){u=normalizeNextDataUrl(u,n,c)}const L=processRoutes(o.beforeFiles,u,f,m);if(L.status){h=L.status}if(L.redirect){return{redirect:L.redirect,resolvedHeaders:f,status:h}}if(L.externalRewrite){return{externalRewrite:L.externalRewrite,resolvedHeaders:f,status:h}}u=L.url;if(p&&l){u=denormalizeNextDataUrl(u,n,c)}let R=matchesPathname(u.pathname,s);if(R){for(const e of o.dynamicRoutes){const t=matchDynamicRoute(u.pathname,e);if(t.matched){const n=checkHasConditions(e.has,u,f);const a=checkMissingConditions(e.missing,u,f);if(n.matched&&a){const e=applyOnMatchHeaders(o.onMatch,f);return{matchedPathname:R,routeMatches:t.params,resolvedHeaders:e,status:h}}}}const e=applyOnMatchHeaders(o.onMatch,f);return{matchedPathname:R,resolvedHeaders:e,status:h}}if(p&&l){u=normalizeNextDataUrl(u,n,c)}for(const e of o.afterFiles){const t=matchRoute(e,u,f);if(t.matched){if(e.headers){for(const[t,n]of Object.entries(e.headers)){f.set(t,n)}}if(e.status){h=e.status}if(t.destination){if(isRedirectStatus(e.status)&&e.headers&&hasRedirectHeaders(e.headers)){const n=isExternalDestination(t.destination)?new URL(t.destination):applyDestination(u,t.destination);return{redirect:{url:n,status:e.status},resolvedHeaders:f,status:h}}if(isExternalDestination(t.destination)){return{externalRewrite:new URL(t.destination),resolvedHeaders:f,status:h}}u=applyDestination(u,t.destination);if(u.origin!==m){return{externalRewrite:u,resolvedHeaders:f,status:h}}const a=checkDynamicRoutes(o.dynamicRoutes,u,s,f,o.onMatch,n,c,l,p);if(a.matched&&a.result){if(a.resetUrl){u=a.resetUrl}return{...a.result,status:h}}let r=u;if(p&&l){r=denormalizeNextDataUrl(u,n,c)}R=matchesPathname(r.pathname,s);if(R){const e=applyOnMatchHeaders(o.onMatch,f);return{matchedPathname:R,resolvedHeaders:e,status:h}}}}}for(const e of o.dynamicRoutes){const t=matchDynamicRoute(u.pathname,e);if(t.matched){const n=checkHasConditions(e.has,u,f);const a=checkMissingConditions(e.missing,u,f);if(n.matched&&a){R=matchesPathname(u.pathname,s);if(R){const e=applyOnMatchHeaders(o.onMatch,f);return{matchedPathname:R,routeMatches:t.params,resolvedHeaders:e,status:h}}}}}for(const e of o.fallback){const t=matchRoute(e,u,f);if(t.matched){if(e.headers){for(const[t,n]of Object.entries(e.headers)){f.set(t,n)}}if(e.status){h=e.status}if(t.destination){if(isRedirectStatus(e.status)&&e.headers&&hasRedirectHeaders(e.headers)){const n=isExternalDestination(t.destination)?new URL(t.destination):applyDestination(u,t.destination);return{redirect:{url:n,status:e.status},resolvedHeaders:f,status:h}}if(isExternalDestination(t.destination)){return{externalRewrite:new URL(t.destination),resolvedHeaders:f,status:h}}u=applyDestination(u,t.destination);if(u.origin!==m){return{externalRewrite:u,resolvedHeaders:f,status:h}}const a=checkDynamicRoutes(o.dynamicRoutes,u,s,f,o.onMatch,n,c,l,p);if(a.matched&&a.result){if(a.resetUrl){u=a.resetUrl}return{...a.result,status:h}}let r=u;if(p&&l){r=denormalizeNextDataUrl(u,n,c)}R=matchesPathname(r.pathname,s);if(R){const e=applyOnMatchHeaders(o.onMatch,f);return{matchedPathname:R,resolvedHeaders:e,status:h}}}}}return{resolvedHeaders:f,status:h}}function responseToMiddlewareResult(e,t,a){const r={};const s={};e.headers.forEach(((e,t)=>{if(s[t]){const n=s[t];if(Array.isArray(n)){n.push(e)}else{s[t]=[n,e]}}else{s[t]=e}}));if(s["x-middleware-override-headers"]){const e=new Set;let n=s["x-middleware-override-headers"];if(typeof n==="string"){n=n.split(",")}for(const t of n){e.add(t.trim())}delete s["x-middleware-override-headers"];const a=[];t.forEach(((t,n)=>{if(!e.has(n)){a.push(n)}}));for(const e of a){t.delete(e)}for(const n of e.keys()){const e="x-middleware-request-"+n;const a=s[e];if(a===undefined||a===null){t.delete(n)}else if(Array.isArray(a)){t.set(n,a[0]);for(let e=1;e<a.length;e++){t.append(n,a[e])}}else{t.set(n,a)}delete s[e]}}if(!s["x-middleware-rewrite"]&&!s["x-middleware-next"]&&!s["location"]){s["x-middleware-refresh"]="1"}delete s["x-middleware-next"];const o=new Headers;for(const[e,n]of Object.entries(s)){if(["content-length","x-middleware-rewrite","x-middleware-redirect","x-middleware-refresh"].includes(e)){continue}if(e==="x-middleware-set-cookie"){if(n!==undefined){if(Array.isArray(n)){for(const a of n){t.append(e,a)}}else{t.set(e,n)}}continue}if(n!==undefined){if(Array.isArray(n)){for(const a of n){o.append(e,a);t.append(e,a)}}else{o.set(e,n);t.set(e,n)}}}r.responseHeaders=o;r.requestHeaders=t;if(s["x-middleware-rewrite"]){const e=s["x-middleware-rewrite"];const t=getRelativeURL(e,a.toString());o.set("x-middleware-rewrite",t);try{const e=new URL(t,a);if(e.origin!==a.origin){r.rewrite=e;return r}r.rewrite=e}catch{r.rewrite=new URL(t,a)}}if(s["location"]){const t=s["location"];const i=n.has(e.status);if(i){const n=getRelativeURL(t,a.toString());o.set("location",n);try{const t=new URL(n,a);r.redirect={url:t,status:e.status};return r}catch{r.redirect={url:new URL(n,a),status:e.status};return r}}else{o.set("location",t);return r}}if(s["x-middleware-refresh"]){r.bodySent=true;return r}return r}function getRelativeURL(e,t){try{const n=new URL(e,t);const a=new URL(t);if(n.origin===a.origin){return n.pathname+n.search+n.hash}return n.toString()}catch{return e}}const n=new Set([301,302,303,307,308]);module.exports=t})();
|
|
1
|
+
(()=>{"use strict";var e={};(()=>{e.d=(t,n)=>{for(var a in n){if(e.o(n,a)&&!e.o(t,a)){Object.defineProperty(t,a,{enumerable:true,get:n[a]})}}}})();(()=>{e.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t)})();(()=>{e.r=e=>{if(typeof Symbol!=="undefined"&&Symbol.toStringTag){Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})}Object.defineProperty(e,"__esModule",{value:true})}})();if(typeof e!=="undefined")e.ab=__dirname+"/";var t={};e.r(t);e.d(t,{detectDomainLocale:()=>detectDomainLocale,detectLocale:()=>detectLocale,getAcceptLanguageLocale:()=>getAcceptLanguageLocale,getCookieLocale:()=>getCookieLocale,normalizeLocalePath:()=>normalizeLocalePath,resolveRoutes:()=>resolveRoutes,responseToMiddlewareResult:()=>responseToMiddlewareResult});function matchesCondition(e,t){if(e===undefined){return{matched:false}}if(t===undefined){return{matched:true,capturedValue:e}}try{const n=new RegExp(t);const a=e.match(n);if(a){return{matched:true,capturedValue:a[0]}}}catch(e){}if(e===t){return{matched:true,capturedValue:e}}return{matched:false}}function getConditionValue(e,t,n){switch(e.type){case"header":return n.get(e.key)||undefined;case"cookie":{const t=n.get("cookie");if(!t)return undefined;const a=t.split(";").reduce(((e,t)=>{const[n,...a]=t.trim().split("=");if(n){e[n]=a.join("=")}return e}),{});return a[e.key]}case"query":return t.searchParams.get(e.key)||undefined;case"host":return t.hostname;default:return""}}function normalizeCaptureKey(e){return e.replace(/[^a-zA-Z]/g,"")}function checkHasConditions(e,t,n){if(!e||e.length===0){return{matched:true,captures:{}}}const a={};for(const r of e){const e=getConditionValue(r,t,n);const s=matchesCondition(e,r.value);if(!s.matched){return{matched:false,captures:{}}}if(s.capturedValue!==undefined&&r.type!=="host"){const e=normalizeCaptureKey(r.key);a[e]=s.capturedValue}}return{matched:true,captures:a}}function checkMissingConditions(e,t,n){if(!e||e.length===0){return true}for(const a of e){const e=getConditionValue(a,t,n);const r=matchesCondition(e,a.value);if(r.matched){return false}}return true}function replaceDestination(e,t,n){let a=e;if(t){for(let e=1;e<t.length;e++){const n=t[e];if(n!==undefined){a=a.replace(new RegExp(`\\$${e}`,"g"),n)}}if(t.groups){for(const[e,n]of Object.entries(t.groups)){if(n!==undefined){a=a.replace(new RegExp(`\\$${e}`,"g"),n)}}}}for(const[e,t]of Object.entries(n)){a=a.replace(new RegExp(`\\$${e}`,"g"),t)}return a}function isExternalDestination(e){return e.startsWith("http://")||e.startsWith("https://")}function applyDestination(e,t){if(isExternalDestination(t)){return new URL(t)}const n=new URL(e.toString());const[a,r]=t.split("?");n.pathname=a;if(r){const e=new URLSearchParams(r);for(const[t,a]of e.entries()){n.searchParams.set(t,a)}}return n}function isRedirectStatus(e){if(!e)return false;return e>=300&&e<400}function hasRedirectHeaders(e){const t=Object.keys(e).map((e=>e.toLowerCase()));return t.includes("location")||t.includes("refresh")}function normalizeNextDataUrl(e,t,n){const a=new URL(e.toString());let r=a.pathname;const s=`${t}/_next/data/${n}/`;if(r.startsWith(s)){let e=r.slice(s.length);if(e.endsWith(".json")){e=e.slice(0,-5)}r=t?`${t}/${e}`:`/${e}`;a.pathname=r}return a}function denormalizeNextDataUrl(e,t,n){const a=new URL(e.toString());let r=a.pathname;const s=`${t}/_next/data/${n}/`;if(!r.startsWith(s)){let e=r;if(t&&r.startsWith(t)){e=r.slice(t.length)}r=`${t}/_next/data/${n}${e}.json`;a.pathname=r}return a}function detectDomainLocale(e,t,n){if(!e)return undefined;const a=t?.toLowerCase();const r=n?.toLowerCase();for(const t of e){const e=t.domain.split(":",1)[0].toLowerCase();if(a===e||r===t.defaultLocale.toLowerCase()||t.locales?.some((e=>e.toLowerCase()===r))){return t}}return undefined}function normalizeLocalePath(e,t){if(!t||t.length===0){return{pathname:e}}const n=e.split("/",2);if(!n[1]){return{pathname:e}}const a=n[1].toLowerCase();const r=t.map((e=>e.toLowerCase()));const s=r.indexOf(a);if(s<0){return{pathname:e}}const o=t[s];const i=e.slice(o.length+1)||"/";return{pathname:i,detectedLocale:o}}function getAcceptLanguageLocale(e,t){if(!e||!t.length){return undefined}try{const n=e.split(",").map((e=>{const t=e.trim().split(";");const n=t[0];let a=1;if(t[1]){const e=t[1].match(/q=([0-9.]+)/);if(e&&e[1]){a=parseFloat(e[1])}}return{locale:n,quality:a}})).filter((e=>e.quality>0)).sort(((e,t)=>t.quality-e.quality));const a=new Map;for(const e of t){a.set(e.toLowerCase(),e)}for(const{locale:e}of n){const t=e.toLowerCase();if(a.has(t)){return a.get(t)}}for(const{locale:e}of n){const t=e.toLowerCase().split("-")[0];if(a.has(t)){return a.get(t)}for(const[e,n]of a){if(e.startsWith(t+"-")){return n}}}return undefined}catch(e){return undefined}}function getCookieLocale(e,t){if(!e||!t.length){return undefined}try{const n=e.split(";").reduce(((e,t)=>{const[n,...a]=t.trim().split("=");if(n&&a.length>0){e[n]=decodeURIComponent(a.join("="))}return e}),{});const a=n.NEXT_LOCALE?.toLowerCase();if(!a){return undefined}return t.find((e=>e.toLowerCase()===a))}catch(e){return undefined}}function detectLocale(e){const{pathname:t,hostname:n,cookieHeader:a,acceptLanguageHeader:r,i18n:s}=e;const o=normalizeLocalePath(t,s.locales);if(o.detectedLocale){return{locale:o.detectedLocale,pathnameWithoutLocale:o.pathname,localeInPath:true}}if(s.localeDetection===false){const e=detectDomainLocale(s.domains,n);return{locale:e?.defaultLocale||s.defaultLocale,pathnameWithoutLocale:t,localeInPath:false}}const i=getCookieLocale(a,s.locales);if(i){return{locale:i,pathnameWithoutLocale:t,localeInPath:false}}const c=getAcceptLanguageLocale(r||"",s.locales);if(c){return{locale:c,pathnameWithoutLocale:t,localeInPath:false}}const d=detectDomainLocale(s.domains,n);if(d){return{locale:d.defaultLocale,pathnameWithoutLocale:t,localeInPath:false}}return{locale:s.defaultLocale,pathnameWithoutLocale:t,localeInPath:false}}function matchRoute(e,t,n){const a=new RegExp(e.sourceRegex);const r=t.pathname.match(a);if(!r){return{matched:false}}const s=checkHasConditions(e.has,t,n);if(!s.matched){return{matched:false}}const o=checkMissingConditions(e.missing,t,n);if(!o){return{matched:false}}const i=e.destination?replaceDestination(e.destination,r,s.captures):undefined;return{matched:true,destination:i,regexMatches:r,hasCaptures:s.captures}}function processRoutes(e,t,n,a){let r=t;let s;for(const t of e){const e=matchRoute(t,r,n);if(e.matched){if(t.headers){for(const[e,a]of Object.entries(t.headers)){n.set(e,a)}}if(t.status){s=t.status}if(e.destination){if(isRedirectStatus(t.status)&&t.headers&&hasRedirectHeaders(t.headers)){const n=isExternalDestination(e.destination)?new URL(e.destination):applyDestination(r,e.destination);return{url:r,redirect:{url:n,status:t.status},stopped:true,status:s}}if(isExternalDestination(e.destination)){return{url:r,externalRewrite:new URL(e.destination),stopped:true,status:s}}r=applyDestination(r,e.destination);if(r.origin!==a){return{url:r,externalRewrite:r,stopped:true,status:s}}}}}return{url:r,stopped:false,status:s}}function matchesPathname(e,t){for(const n of t){if(e===n){return n}}return undefined}function matchDynamicRoute(e,t){const n=new RegExp(t.sourceRegex);const a=e.match(n);if(!a){return{matched:false}}const r={};for(let e=1;e<a.length;e++){if(a[e]!==undefined){r[String(e)]=a[e]}}if(a.groups){Object.assign(r,a.groups)}let s;if(t.destination){const e=replaceDestination(t.destination,a,{});const[n]=e.split("?");s=n}return{matched:true,params:r,destinationPathname:s}}function applyOnMatchHeaders(e,t){const n=new Headers(t);for(const t of e){if(t.headers){for(const[e,a]of Object.entries(t.headers)){n.set(e,a)}}}return n}function checkDynamicRoutes(e,t,n,a,r,s,o,i,c){let d=t;if(c&&i){d=denormalizeNextDataUrl(t,s,o)}for(const t of e){const e=matchDynamicRoute(d.pathname,t);if(e.matched){const s=checkHasConditions(t.has,d,a);const o=checkMissingConditions(t.missing,d,a);if(s.matched&&o){const t=e.destinationPathname||d.pathname;const s=matchesPathname(t,n);if(s){const t=applyOnMatchHeaders(r,a);return{matched:true,result:{matchedPathname:s,routeMatches:e.params,resolvedHeaders:t},resetUrl:d}}}}}return{matched:false}}async function resolveRoutes(e){const{url:t,basePath:n,requestBody:a,headers:r,pathnames:s,routes:o,invokeMiddleware:i,buildId:c,i18n:d}=e;const{shouldNormalizeNextData:l}=o;let u=new URL(t.toString());let f=new Headers(r);let h;const m=t.origin;let p=false;if(l){const e=`${n}/_next/data/${c}/`;p=t.pathname.startsWith(e);if(p){u=normalizeNextDataUrl(u,n,c)}}if(d&&!p){const e=u.pathname.startsWith(n)?u.pathname.slice(n.length)||"/":u.pathname;if(!e.startsWith("/_next/")&&!e.startsWith("/api/")){const t=u.hostname;const a=f.get("cookie")||undefined;const r=f.get("accept-language")||undefined;const s=normalizeLocalePath(e,d.locales);const o=!!s.detectedLocale;const i=detectDomainLocale(d.domains,t);const c=i?.defaultLocale||d.defaultLocale;let l=s.detectedLocale||c;if(d.localeDetection!==false&&!o){const s=detectLocale({pathname:e,hostname:t,cookieHeader:a,acceptLanguageHeader:r,i18n:d});l=s.locale;if(l!==c){const a=detectDomainLocale(d.domains,undefined,l);if(a&&a.domain!==t){const t=a.http?"http":"https";const r=l===a.defaultLocale?"":`/${l}`;const s=new URL(`${t}://${a.domain}${n}${r}${e}${u.search}`);return{redirect:{url:s,status:307},resolvedHeaders:f}}if(!a||a&&a.domain===t){const t=new URL(u.toString());t.pathname=`${n}/${l}${e}`;return{redirect:{url:t,status:307},resolvedHeaders:f}}}}if(!o){const t=l||i?.defaultLocale||d.defaultLocale;u.pathname=`${n}/${t}${e}`}}}const g=processRoutes(o.beforeMiddleware,u,f,m);if(g.status){h=g.status}if(g.redirect){return{redirect:g.redirect,resolvedHeaders:f,status:h}}if(g.externalRewrite){return{externalRewrite:g.externalRewrite,resolvedHeaders:f,status:h}}u=g.url;if(p&&l){u=denormalizeNextDataUrl(u,n,c)}const w=await i({url:u,headers:f,requestBody:a});if(w.bodySent){return{middlewareResponded:true}}if(w.requestHeaders){f=new Headers(w.requestHeaders)}if(w.redirect){f.set("Location",w.redirect.url.toString());return{resolvedHeaders:f,status:w.redirect.status}}if(w.rewrite){u=w.rewrite;if(u.origin!==m){return{externalRewrite:u,resolvedHeaders:f,status:h}}}if(p&&l){u=normalizeNextDataUrl(u,n,c)}const L=processRoutes(o.beforeFiles,u,f,m);if(L.status){h=L.status}if(L.redirect){return{redirect:L.redirect,resolvedHeaders:f,status:h}}if(L.externalRewrite){return{externalRewrite:L.externalRewrite,resolvedHeaders:f,status:h}}u=L.url;if(p&&l){u=denormalizeNextDataUrl(u,n,c)}let R=matchesPathname(u.pathname,s);if(R){for(const e of o.dynamicRoutes){const t=matchDynamicRoute(u.pathname,e);if(t.matched){const n=checkHasConditions(e.has,u,f);const a=checkMissingConditions(e.missing,u,f);if(n.matched&&a){const e=applyOnMatchHeaders(o.onMatch,f);return{matchedPathname:R,routeMatches:t.params,resolvedHeaders:e,status:h}}}}const e=applyOnMatchHeaders(o.onMatch,f);return{matchedPathname:R,resolvedHeaders:e,status:h}}if(p&&l){u=normalizeNextDataUrl(u,n,c)}for(const e of o.afterFiles){const t=matchRoute(e,u,f);if(t.matched){if(e.headers){for(const[t,n]of Object.entries(e.headers)){f.set(t,n)}}if(e.status){h=e.status}if(t.destination){if(isRedirectStatus(e.status)&&e.headers&&hasRedirectHeaders(e.headers)){const n=isExternalDestination(t.destination)?new URL(t.destination):applyDestination(u,t.destination);return{redirect:{url:n,status:e.status},resolvedHeaders:f,status:h}}if(isExternalDestination(t.destination)){return{externalRewrite:new URL(t.destination),resolvedHeaders:f,status:h}}u=applyDestination(u,t.destination);if(u.origin!==m){return{externalRewrite:u,resolvedHeaders:f,status:h}}const a=checkDynamicRoutes(o.dynamicRoutes,u,s,f,o.onMatch,n,c,l,p);if(a.matched&&a.result){if(a.resetUrl){u=a.resetUrl}return{...a.result,status:h}}let r=u;if(p&&l){r=denormalizeNextDataUrl(u,n,c)}R=matchesPathname(r.pathname,s);if(R){const e=applyOnMatchHeaders(o.onMatch,f);return{matchedPathname:R,resolvedHeaders:e,status:h}}}}}for(const e of o.dynamicRoutes){const t=matchDynamicRoute(u.pathname,e);if(t.matched){const n=checkHasConditions(e.has,u,f);const a=checkMissingConditions(e.missing,u,f);if(n.matched&&a){const e=t.destinationPathname||u.pathname;R=matchesPathname(e,s);if(R){const e=applyOnMatchHeaders(o.onMatch,f);return{matchedPathname:R,routeMatches:t.params,resolvedHeaders:e,status:h}}}}}for(const e of o.fallback){const t=matchRoute(e,u,f);if(t.matched){if(e.headers){for(const[t,n]of Object.entries(e.headers)){f.set(t,n)}}if(e.status){h=e.status}if(t.destination){if(isRedirectStatus(e.status)&&e.headers&&hasRedirectHeaders(e.headers)){const n=isExternalDestination(t.destination)?new URL(t.destination):applyDestination(u,t.destination);return{redirect:{url:n,status:e.status},resolvedHeaders:f,status:h}}if(isExternalDestination(t.destination)){return{externalRewrite:new URL(t.destination),resolvedHeaders:f,status:h}}u=applyDestination(u,t.destination);if(u.origin!==m){return{externalRewrite:u,resolvedHeaders:f,status:h}}const a=checkDynamicRoutes(o.dynamicRoutes,u,s,f,o.onMatch,n,c,l,p);if(a.matched&&a.result){if(a.resetUrl){u=a.resetUrl}return{...a.result,status:h}}let r=u;if(p&&l){r=denormalizeNextDataUrl(u,n,c)}R=matchesPathname(r.pathname,s);if(R){const e=applyOnMatchHeaders(o.onMatch,f);return{matchedPathname:R,resolvedHeaders:e,status:h}}}}}return{resolvedHeaders:f,status:h}}function responseToMiddlewareResult(e,t,a){const r={};const s={};e.headers.forEach(((e,t)=>{if(s[t]){const n=s[t];if(Array.isArray(n)){n.push(e)}else{s[t]=[n,e]}}else{s[t]=e}}));if(s["x-middleware-override-headers"]){const e=new Set;let n=s["x-middleware-override-headers"];if(typeof n==="string"){n=n.split(",")}for(const t of n){e.add(t.trim())}delete s["x-middleware-override-headers"];const a=[];t.forEach(((t,n)=>{if(!e.has(n)){a.push(n)}}));for(const e of a){t.delete(e)}for(const n of e.keys()){const e="x-middleware-request-"+n;const a=s[e];if(a===undefined||a===null){t.delete(n)}else if(Array.isArray(a)){t.set(n,a[0]);for(let e=1;e<a.length;e++){t.append(n,a[e])}}else{t.set(n,a)}delete s[e]}}if(!s["x-middleware-rewrite"]&&!s["x-middleware-next"]&&!s["location"]){s["x-middleware-refresh"]="1"}delete s["x-middleware-next"];const o=new Headers;for(const[e,n]of Object.entries(s)){if(["content-length","x-middleware-rewrite","x-middleware-redirect","x-middleware-refresh"].includes(e)){continue}if(e==="x-middleware-set-cookie"){if(n!==undefined){if(Array.isArray(n)){for(const a of n){t.append(e,a)}}else{t.set(e,n)}}continue}if(n!==undefined){if(Array.isArray(n)){for(const a of n){o.append(e,a);t.append(e,a)}}else{o.set(e,n);t.set(e,n)}}}r.responseHeaders=o;r.requestHeaders=t;if(s["x-middleware-rewrite"]){const e=s["x-middleware-rewrite"];const t=getRelativeURL(e,a.toString());o.set("x-middleware-rewrite",t);try{const e=new URL(t,a);if(e.origin!==a.origin){r.rewrite=e;return r}r.rewrite=e}catch{r.rewrite=new URL(t,a)}}if(s["location"]){const t=s["location"];const i=n.has(e.status);if(i){const n=getRelativeURL(t,a.toString());o.set("location",n);try{const t=new URL(n,a);r.redirect={url:t,status:e.status};return r}catch{r.redirect={url:new URL(n,a),status:e.status};return r}}else{o.set("location",t);return r}}if(s["x-middleware-refresh"]){r.bodySent=true;return r}return r}function getRelativeURL(e,t){try{const n=new URL(e,t);const a=new URL(t);if(n.origin===a.origin){return n.pathname+n.search+n.hash}return n.toString()}catch{return e}}const n=new Set([301,302,303,307,308]);module.exports=t})();
|