@next/routing 16.5.0-canary.6 → 16.5.0-canary.60

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/README.md CHANGED
@@ -68,6 +68,7 @@ Each route can have:
68
68
  ### Redirects
69
69
 
70
70
  When a route has:
71
+
71
72
  - A redirect status code (300-399)
72
73
  - Headers containing `Location` or `Refresh`
73
74
 
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=new RegExp(t);const s=e.match(n)??e.match(a);if(s){const e={};if(s.groups){for(const[t,n]of Object.entries(s.groups)){if(typeof n==="string"&&n.length>0){e[t]=n}}}return{matched:true,capturedValue:s[0],...Object.keys(e).length>0?{namedCaptures:e}:{}}}}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 s of e){const e=getConditionValue(s,t,n);const r=matchesCondition(e,s.value);if(!r.matched){return{matched:false,captures:{}}}if(r.namedCaptures){for(const[e,t]of Object.entries(r.namedCaptures)){a[e]=t}}if(r.capturedValue!==undefined&&s.type!=="host"){const e=normalizeCaptureKey(s.key);a[e]=r.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 s=matchesCondition(e,a.value);if(s.matched){return false}}return true}function replaceDestination(e,t,n){const a=Object.keys(n);if(t){for(let e=1;e<t.length;e++){a.push(String(e))}if(t.groups){a.push(...Object.keys(t.groups))}}if(a.length===0){return e}const s=a.sort(((e,t)=>t.length-e.length)).map((e=>{const t=e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");return/^\d+$/.test(e)?`${t}(?!\\d)`:t})).join("|");return e.replace(new RegExp(`\\$(${s})`,"g"),((e,a)=>{if(t){const e=Number(a);if(Number.isInteger(e)&&e>0&&e<t.length&&String(e)===a){return t[e]??""}if(t.groups&&Object.hasOwn(t.groups,a)){return t.groups[a]??""}}if(Object.hasOwn(n,a)){return n[a]}return e}))}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,s]=t.split("?");n.pathname=a;if(s){const e=new URLSearchParams(s);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 s=a.pathname;const r=`${t}/_next/data/${n}/`;if(s.startsWith(r)){let e=s.slice(r.length);if(e.endsWith(".json")){e=e.slice(0,-5)}if(e==="index"){s=t||"/"}else{s=t?`${t}/${e}`:`/${e}`}a.pathname=s}return a}function denormalizeNextDataUrl(e,t,n){const a=new URL(e.toString());let s=a.pathname;const r=`${t}/_next/data/${n}/`;if(!s.startsWith(r)){let e=s;if(t&&s.startsWith(t)){e=s.slice(t.length)}if(e===""||e==="/"){e="/index"}s=`${t}/_next/data/${n}${e}.json`;a.pathname=s}return a}function detectDomainLocale(e,t,n){if(!e)return undefined;const a=t?.toLowerCase();const s=n?.toLowerCase();for(const t of e){const e=t.domain.split(":",1)[0].toLowerCase();if(a===e||s===t.defaultLocale.toLowerCase()||t.locales?.some((e=>e.toLowerCase()===s))){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 s=t.map((e=>e.toLowerCase()));const r=s.indexOf(a);if(r<0){return{pathname:e}}const o=t[r];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:s,i18n:r}=e;const o=normalizeLocalePath(t,r.locales);if(o.detectedLocale){return{locale:o.detectedLocale,pathnameWithoutLocale:o.pathname,localeInPath:true}}if(r.localeDetection===false){const e=detectDomainLocale(r.domains,n);return{locale:e?.defaultLocale||r.defaultLocale,pathnameWithoutLocale:t,localeInPath:false}}const i=getCookieLocale(a,r.locales);if(i){return{locale:i,pathnameWithoutLocale:t,localeInPath:false}}const c=getAcceptLanguageLocale(s||"",r.locales);if(c){return{locale:c,pathnameWithoutLocale:t,localeInPath:false}}const l=detectDomainLocale(r.domains,n);if(l){return{locale:l.defaultLocale,pathnameWithoutLocale:t,localeInPath:false}}return{locale:r.defaultLocale,pathnameWithoutLocale:t,localeInPath:false}}function getHeaderValueCaseInsensitive(e,t){const n=t.toLowerCase();for(const[t,a]of Object.entries(e)){if(t.toLowerCase()===n){return a}}return undefined}function resolveRedirectLocationWithRequestQuery(e,t){if(!t.search){return e}try{const n=new URL(e,t);if(n.search){return e}n.search=t.search;if(n.origin!==t.origin){return n.toString()}return`${n.pathname}${n.search}${n.hash}`}catch{return e}}function matchRoute(e,t,n,a){const s=new RegExp(e.sourceRegex,a?"":"i");const r=t.pathname.match(s);if(!r){return{matched:false}}const o=checkHasConditions(e.has,t,n);if(!o.matched){return{matched:false}}const i=checkMissingConditions(e.missing,t,n);if(!i){return{matched:false}}const c=e.destination?replaceDestination(e.destination,r,o.captures):undefined;const l=e.headers?Object.fromEntries(Object.entries(e.headers).map((([e,t])=>[replaceDestination(e,r,o.captures),replaceDestination(t,r,o.captures)]))):undefined;return{matched:true,destination:c,headers:l,regexMatches:r,hasCaptures:o.captures}}function processRoutes(e,t,n,a,s,r){let o=t;let i;for(const t of e){const e=matchRoute(t,o,n,r);if(e.matched){if(e.headers){for(const[t,n]of Object.entries(e.headers)){a.set(t,n)}}if(t.status){i=t.status}if(isRedirectStatus(t.status)&&e.headers&&hasRedirectHeaders(e.headers)){if(e.destination){const n=isExternalDestination(e.destination)?new URL(e.destination):applyDestination(o,e.destination);return{url:o,redirect:{url:n,status:t.status},stopped:true,status:i}}const n=getHeaderValueCaseInsensitive(e.headers,"location");if(n){a.set("location",resolveRedirectLocationWithRequestQuery(n,o))}return{url:o,stopped:true,status:i}}if(e.destination){if(isExternalDestination(e.destination)){return{url:o,externalRewrite:new URL(e.destination),stopped:true,status:i}}o=applyDestination(o,e.destination);if(o.origin!==s){return{url:o,externalRewrite:o,stopped:true,status:i}}}}}return{url:o,stopped:false,status:i}}function matchesPathname(e,t){for(const n of t){if(e===n){return n}}return undefined}function matchesPathnameWithLocaleFallback({pathname:e,pathnames:t,basePath:n,i18n:a}){const s=matchesPathname(e,t);if(s||!a){return s}const r=n&&e.startsWith(n)?e.slice(n.length)||"/":e;for(const e of a.locales){const a=`/${e}`;if(r!==a&&!r.startsWith(`${a}/`)){continue}const s=r===a?"/":r.slice(a.length)||"/";const o=n?`${n}${s}`:s;const i=matchesPathname(o,t);if(i){return i}}return undefined}function isDynamicTemplatePathname(e){return/\[[^/]+?\]/.test(e)}function toResolvedQuery(e){const t={};for(const[n,a]of e.searchParams.entries()){const e=t[n];if(e===undefined){t[n]=a;continue}t[n]=Array.isArray(e)?[...e,a]:[e,a]}return t}function mergeDestinationQueryIntoUrl(e,t){const n=new URL(e.toString());const a=t.split("?")[1];if(!a){return n}const s=new URLSearchParams(a);for(const[e,t]of s.entries()){n.searchParams.set(e,t)}return n}function withResolvedInvocationTarget({result:e,url:t,resolvedPathname:n,invocationPathname:a}){const s=toResolvedQuery(t);return{...e,resolvedPathname:n,resolvedQuery:s,invocationTarget:{pathname:a,query:s}}}function matchDynamicRoute(e,t,n){const a=new RegExp(t.sourceRegex,n?"":"i");const s=e.match(a);if(!s){return{matched:false}}const r={};for(let e=1;e<s.length;e++){if(s[e]!==undefined){r[String(e)]=s[e]}}if(s.groups){Object.assign(r,s.groups)}return{matched:true,params:r,regexMatches:s}}function applyOnMatchHeaders(e,t,n,a,s){const r=new Headers(a);for(const a of e){const e=matchRoute(a,t,n,s);if(e.matched&&e.headers){for(const[t,n]of Object.entries(e.headers)){r.set(t,n)}}}return r}function checkDynamicRoutes(e,t,n,a,s,r,o,i,c,l,u,d=false){let f=t;if(u&&l){f=denormalizeNextDataUrl(t,o,i)}for(const t of e){const e=matchDynamicRoute(f.pathname,t,d);if(e.matched){const i=checkHasConditions(t.has,f,a);const l=checkMissingConditions(t.missing,f,a);if(i.matched&&l){const l=t.destination?replaceDestination(t.destination,e.regexMatches||null,i.captures):undefined;const u=l?l.split("?")[0]:f.pathname;const h=matchesPathnameWithLocaleFallback({pathname:u,pathnames:n,basePath:o,i18n:c});if(h){const t=l?mergeDestinationQueryIntoUrl(f,l):f;const n=applyOnMatchHeaders(r,t,a,s,d);const o=withResolvedInvocationTarget({result:{routeMatches:e.params,resolvedHeaders:n},url:t,resolvedPathname:h,invocationPathname:f.pathname});return{matched:true,result:o,resetUrl:f}}}}}return{matched:false}}function shouldInvokeMiddlewareForRequest(e,t,n,a){const matchesMiddlewareMatchers=s=>{if(!e||e.length===0){return false}for(const r of e){const e=new RegExp(r.sourceRegex,a?"":"i");const o=s.match(e);if(!o){continue}const i=checkHasConditions(r.has,t,n);if(!i.matched){continue}const c=checkMissingConditions(r.missing,t,n);if(!c){continue}return true}return false};if(e===undefined){return true}if(e.length===0){return false}if(matchesMiddlewareMatchers(t.pathname)){return true}let s=t.pathname;try{s=decodeURIComponent(t.pathname)}catch{return false}if(s===t.pathname){return false}return matchesMiddlewareMatchers(s)}async function resolveRoutes(e){const{url:t,basePath:n,requestBody:a,headers:s,pathnames:r,routes:o,invokeMiddleware:i,buildId:c,i18n:l}=e;const{shouldNormalizeNextData:u,caseSensitive:d=false}=o;let f=new URL(t.toString());let h=new Headers(s);let m=new Headers;let p;let g;let w;const R=t.origin;let L=false;if(u){const e=`${n}/_next/data/${c}/`;L=t.pathname.startsWith(e);if(L){f=normalizeNextDataUrl(f,n,c)}}if(l&&!L){const e=f.pathname.startsWith(n)?f.pathname.slice(n.length)||"/":f.pathname;if(!e.startsWith("/_next/")&&!e.startsWith("/api/")){const t=f.hostname;const a=h.get("cookie")||undefined;const s=h.get("accept-language")||undefined;const r=normalizeLocalePath(e,l.locales);const o=!!r.detectedLocale;const i=detectDomainLocale(l.domains,t);const c=i?.defaultLocale||l.defaultLocale;let u=r.detectedLocale||c;const d=l.localeDetection!==false&&!o&&r.pathname==="/";if(d){const r=detectLocale({pathname:e,hostname:t,cookieHeader:a,acceptLanguageHeader:s,i18n:l});u=r.locale;if(u!==c){const a=detectDomainLocale(l.domains,undefined,u);if(a&&a.domain!==t){const t=a.http?"http":"https";const s=u===a.defaultLocale?"":`/${u}`;const r=new URL(`${t}://${a.domain}${n}${s}${e}${f.search}`);g={url:r,status:307}}if(!a||a&&a.domain===t){const t=new URL(f.toString());t.pathname=`${n}/${u}${e}`;g={url:t,status:307}}}}if(!o&&!g){const t=u||i?.defaultLocale||l.defaultLocale;f.pathname=`${n}/${t}${e}`}}}const y=processRoutes(o.beforeMiddleware,f,h,m,R,d);if(y.status){p=y.status}if(y.redirect){return{redirect:y.redirect,resolvedHeaders:m,status:p}}if(y.externalRewrite){return{externalRewrite:y.externalRewrite,resolvedHeaders:m,status:p}}if(y.stopped){w={status:p}}f=y.url;let v=f;if(L&&u){v=denormalizeNextDataUrl(f,n,c)}const x=shouldInvokeMiddlewareForRequest(o.middlewareMatchers,f,h,d);if(x){const e=await i({url:v,headers:h,requestBody:a});if(e.bodySent){return{middlewareResponded:true}}if(e.requestHeaders){h=new Headers(e.requestHeaders)}if(e.responseHeaders){e.responseHeaders.forEach(((e,t)=>{if(t.toLowerCase()==="set-cookie"){m.append(t,e)}else{m.set(t,e)}}))}if(e.redirect){if(!m.has("location")){m.set("Location",e.redirect.url.toString())}return{resolvedHeaders:m,status:e.redirect.status}}if(e.rewrite){f=e.rewrite;if(f.origin!==R){return{externalRewrite:f,resolvedHeaders:m,status:p}}}}if(g){if(!m.has("location")){m.set("location",g.url.toString())}return{redirect:g,resolvedHeaders:m}}if(w){return{resolvedHeaders:m,status:w.status}}if(L&&u){f=normalizeNextDataUrl(f,n,c)}const H=processRoutes(o.beforeFiles,f,h,m,R,d);if(H.status){p=H.status}if(H.redirect){return{redirect:H.redirect,resolvedHeaders:m,status:p}}if(H.externalRewrite){return{externalRewrite:H.externalRewrite,resolvedHeaders:m,status:p}}if(H.stopped){return{resolvedHeaders:m,status:p}}f=H.url;if(L&&u){f=denormalizeNextDataUrl(f,n,c)}let D=matchesPathname(f.pathname,r);if(D){for(const e of o.dynamicRoutes){const t=matchDynamicRoute(f.pathname,e,d);if(!t.matched){continue}const a=checkHasConditions(e.has,f,h);const s=checkMissingConditions(e.missing,f,h);if(!a.matched||!s){continue}const i=e.destination?replaceDestination(e.destination,t.regexMatches||null,a.captures):undefined;const c=i?i.split("?")[0]:f.pathname;const u=matchesPathnameWithLocaleFallback({pathname:c,pathnames:r,basePath:n,i18n:l});if(!u){if(isDynamicTemplatePathname(c)){continue}const e=i?mergeDestinationQueryIntoUrl(f,i):f;const n=applyOnMatchHeaders(o.onMatch,e,h,m,d);return withResolvedInvocationTarget({result:{routeMatches:t.params,resolvedHeaders:n,status:p},url:e,resolvedPathname:D,invocationPathname:f.pathname})}const g=u===D||isDynamicTemplatePathname(D);if(!g){continue}const w=i?mergeDestinationQueryIntoUrl(f,i):f;const R=applyOnMatchHeaders(o.onMatch,w,h,m,d);return withResolvedInvocationTarget({result:{routeMatches:t.params,resolvedHeaders:R,status:p},url:w,resolvedPathname:u,invocationPathname:f.pathname})}const e=applyOnMatchHeaders(o.onMatch,f,h,m,d);return withResolvedInvocationTarget({result:{resolvedHeaders:e,status:p},url:f,resolvedPathname:D,invocationPathname:f.pathname})}if(L&&u){f=normalizeNextDataUrl(f,n,c)}for(const e of o.afterFiles){const t=matchRoute(e,f,h,d);if(t.matched){if(t.headers){for(const[e,n]of Object.entries(t.headers)){m.set(e,n)}}if(e.status){p=e.status}if(t.destination){if(isRedirectStatus(e.status)&&t.headers&&hasRedirectHeaders(t.headers)){const n=isExternalDestination(t.destination)?new URL(t.destination):applyDestination(f,t.destination);return{redirect:{url:n,status:e.status},resolvedHeaders:m,status:p}}if(isExternalDestination(t.destination)){return{externalRewrite:new URL(t.destination),resolvedHeaders:m,status:p}}f=applyDestination(f,t.destination);if(f.origin!==R){return{externalRewrite:f,resolvedHeaders:m,status:p}}const a=checkDynamicRoutes(o.dynamicRoutes,f,r,h,m,o.onMatch,n,c,l,u,L,d);if(a.matched&&a.result){if(a.resetUrl){f=a.resetUrl}return{...a.result,status:p}}let s=f;if(L&&u){s=denormalizeNextDataUrl(f,n,c)}D=matchesPathname(s.pathname,r);if(D){const e=applyOnMatchHeaders(o.onMatch,s,h,m,d);return withResolvedInvocationTarget({result:{resolvedHeaders:e,status:p},url:s,resolvedPathname:D,invocationPathname:s.pathname})}}}}for(const e of o.dynamicRoutes){const t=matchDynamicRoute(f.pathname,e,d);if(t.matched){const a=checkHasConditions(e.has,f,h);const s=checkMissingConditions(e.missing,f,h);if(a.matched&&s){const s=e.destination?replaceDestination(e.destination,t.regexMatches||null,a.captures):undefined;const i=s?s.split("?")[0]:f.pathname;D=matchesPathnameWithLocaleFallback({pathname:i,pathnames:r,basePath:n,i18n:l});if(D){const e=s?mergeDestinationQueryIntoUrl(f,s):f;const n=applyOnMatchHeaders(o.onMatch,e,h,m,d);return withResolvedInvocationTarget({result:{routeMatches:t.params,resolvedHeaders:n,status:p},url:e,resolvedPathname:D,invocationPathname:f.pathname})}}}}for(const e of o.fallback){const t=matchRoute(e,f,h,d);if(t.matched){if(t.headers){for(const[e,n]of Object.entries(t.headers)){m.set(e,n)}}if(e.status){p=e.status}if(t.destination){if(isRedirectStatus(e.status)&&t.headers&&hasRedirectHeaders(t.headers)){const n=isExternalDestination(t.destination)?new URL(t.destination):applyDestination(f,t.destination);return{redirect:{url:n,status:e.status},resolvedHeaders:m,status:p}}if(isExternalDestination(t.destination)){return{externalRewrite:new URL(t.destination),resolvedHeaders:m,status:p}}f=applyDestination(f,t.destination);if(f.origin!==R){return{externalRewrite:f,resolvedHeaders:m,status:p}}const a=checkDynamicRoutes(o.dynamicRoutes,f,r,h,m,o.onMatch,n,c,l,u,L,d);if(a.matched&&a.result){if(a.resetUrl){f=a.resetUrl}return{...a.result,status:p}}let s=f;if(L&&u){s=denormalizeNextDataUrl(f,n,c)}D=matchesPathname(s.pathname,r);if(D){const e=applyOnMatchHeaders(o.onMatch,s,h,m,d);return withResolvedInvocationTarget({result:{resolvedHeaders:e,status:p},url:s,resolvedPathname:D,invocationPathname:s.pathname})}}}}return{resolvedHeaders:m,status:p}}function responseToMiddlewareResult(e,t,a){const s={};const r={};e.headers.forEach(((e,t)=>{if(r[t]){const n=r[t];if(Array.isArray(n)){n.push(e)}else{r[t]=[n,e]}}else{r[t]=e}}));if(r["x-middleware-override-headers"]){const e=new Set;let n=r["x-middleware-override-headers"];if(typeof n==="string"){n=n.split(",")}for(const t of n){e.add(t.trim())}delete r["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=r[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 r[e]}}if(!r["x-middleware-rewrite"]&&!r["x-middleware-next"]&&!r["location"]){r["x-middleware-refresh"]="1"}delete r["x-middleware-next"];const o=new Headers;for(const[e,n]of Object.entries(r)){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)}}}s.responseHeaders=o;s.requestHeaders=t;if(r["x-middleware-rewrite"]){const e=r["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){s.rewrite=e;return s}s.rewrite=e}catch{s.rewrite=new URL(t,a)}}if(r["location"]){const t=r["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);s.redirect={url:t,status:e.status};return s}catch{s.redirect={url:new URL(n,a),status:e.status};return s}}else{o.set("location",t);return s}}if(r["x-middleware-refresh"]){s.bodySent=true;return s}return s}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=new RegExp(t);const s=e.match(n)??e.match(a);if(s){const e={};if(s.groups){for(const[t,n]of Object.entries(s.groups)){if(typeof n==="string"&&n.length>0){e[t]=n}}}return{matched:true,capturedValue:s[0],...Object.keys(e).length>0?{namedCaptures:e}:{}}}}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 s of e){const e=getConditionValue(s,t,n);const r=matchesCondition(e,s.value);if(!r.matched){return{matched:false,captures:{}}}if(r.namedCaptures){for(const[e,t]of Object.entries(r.namedCaptures)){a[e]=t}}if(r.capturedValue!==undefined&&s.type!=="host"){const e=normalizeCaptureKey(s.key);a[e]=r.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 s=matchesCondition(e,a.value);if(s.matched){return false}}return true}function replaceDestination(e,t,n){const a=Object.keys(n);if(t){for(let e=1;e<t.length;e++){a.push(String(e))}if(t.groups){a.push(...Object.keys(t.groups))}}if(a.length===0){return e}const s=a.sort(((e,t)=>t.length-e.length)).map((e=>{const t=e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");return/^\d+$/.test(e)?`${t}(?!\\d)`:t})).join("|");return e.replace(new RegExp(`\\$(${s})`,"g"),((e,a)=>{if(t){const e=Number(a);if(Number.isInteger(e)&&e>0&&e<t.length&&String(e)===a){return t[e]??""}if(t.groups&&Object.hasOwn(t.groups,a)){return t.groups[a]??""}}if(Object.hasOwn(n,a)){return n[a]}return e}))}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,s]=t.split("?");n.pathname=a;if(s){const e=new URLSearchParams(s);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 s=a.pathname;const r=`${t}/_next/data/${n}/`;if(s.startsWith(r)){let e=s.slice(r.length);if(e.endsWith(".json")){e=e.slice(0,-5)}if(e==="index"){s=t||"/"}else{s=t?`${t}/${e}`:`/${e}`}a.pathname=s}return a}function denormalizeNextDataUrl(e,t,n){const a=new URL(e.toString());let s=a.pathname;const r=`${t}/_next/data/${n}/`;if(!s.startsWith(r)){let e=s;if(t&&s.startsWith(t)){e=s.slice(t.length)}if(e===""||e==="/"){e="/index"}s=`${t}/_next/data/${n}${e}.json`;a.pathname=s}return a}function detectDomainLocale(e,t,n){if(!e)return undefined;const a=t?.toLowerCase();const s=n?.toLowerCase();for(const t of e){const e=t.domain.split(":",1)[0].toLowerCase();if(a===e||s===t.defaultLocale.toLowerCase()||t.locales?.some((e=>e.toLowerCase()===s))){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 s=t.map((e=>e.toLowerCase()));const r=s.indexOf(a);if(r<0){return{pathname:e}}const o=t[r];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:s,i18n:r}=e;const o=normalizeLocalePath(t,r.locales);if(o.detectedLocale){return{locale:o.detectedLocale,pathnameWithoutLocale:o.pathname,localeInPath:true}}if(r.localeDetection===false){const e=detectDomainLocale(r.domains,n);return{locale:e?.defaultLocale||r.defaultLocale,pathnameWithoutLocale:t,localeInPath:false}}const i=getCookieLocale(a,r.locales);if(i){return{locale:i,pathnameWithoutLocale:t,localeInPath:false}}const c=getAcceptLanguageLocale(s||"",r.locales);if(c){return{locale:c,pathnameWithoutLocale:t,localeInPath:false}}const u=detectDomainLocale(r.domains,n);if(u){return{locale:u.defaultLocale,pathnameWithoutLocale:t,localeInPath:false}}return{locale:r.defaultLocale,pathnameWithoutLocale:t,localeInPath:false}}function getHeaderValueCaseInsensitive(e,t){const n=t.toLowerCase();for(const[t,a]of Object.entries(e)){if(t.toLowerCase()===n){return a}}return undefined}function resolveRedirectLocationWithRequestQuery(e,t){if(!t.search){return e}try{const n=new URL(e,t);if(n.search){return e}n.search=t.search;if(n.origin!==t.origin){return n.toString()}return`${n.pathname}${n.search}${n.hash}`}catch{return e}}function matchRoute(e,t,n,a){const s=new RegExp(e.sourceRegex,a?"":"i");const r=t.pathname.match(s);if(!r){return{matched:false}}const o=checkHasConditions(e.has,t,n);if(!o.matched){return{matched:false}}const i=checkMissingConditions(e.missing,t,n);if(!i){return{matched:false}}const c=e.destination?replaceDestination(e.destination,r,o.captures):undefined;const u=e.headers?Object.fromEntries(Object.entries(e.headers).map((([e,t])=>[replaceDestination(e,r,o.captures),replaceDestination(t,r,o.captures)]))):undefined;return{matched:true,destination:c,headers:u,regexMatches:r,hasCaptures:o.captures}}function processRoutes(e,t,n,a,s,r){let o=t;let i;for(const t of e){const e=matchRoute(t,o,n,r);if(e.matched){if(e.headers){for(const[t,n]of Object.entries(e.headers)){a.set(t,n)}}if(t.status){i=t.status}if(isRedirectStatus(t.status)&&e.headers&&hasRedirectHeaders(e.headers)){if(e.destination){const n=isExternalDestination(e.destination)?new URL(e.destination):applyDestination(o,e.destination);return{url:o,redirect:{url:n,status:t.status},stopped:true,status:i}}const n=getHeaderValueCaseInsensitive(e.headers,"location");if(n){a.set("location",resolveRedirectLocationWithRequestQuery(n,o))}return{url:o,stopped:true,status:i}}if(e.destination){if(isExternalDestination(e.destination)){return{url:o,externalRewrite:new URL(e.destination),stopped:true,status:i}}o=applyDestination(o,e.destination);if(o.origin!==s){return{url:o,externalRewrite:o,stopped:true,status:i}}}}}return{url:o,stopped:false,status:i}}function matchesPathname(e,t){for(const n of t){if(e===n){return n}}return undefined}function matchesPathnameWithLocaleFallback({pathname:e,pathnames:t,basePath:n,i18n:a}){const s=matchesPathname(e,t);if(s||!a){return s}const r=n&&e.startsWith(n)?e.slice(n.length)||"/":e;for(const e of a.locales){const a=`/${e}`;if(r!==a&&!r.startsWith(`${a}/`)){continue}const s=r===a?"/":r.slice(a.length)||"/";const o=n?`${n}${s}`:s;const i=matchesPathname(o,t);if(i){return i}}return undefined}function isDynamicTemplatePathname(e){return/\[[^/]+?\]/.test(e)}function toResolvedQuery(e){const t={};for(const[n,a]of e.searchParams.entries()){const e=t[n];if(e===undefined){t[n]=a;continue}t[n]=Array.isArray(e)?[...e,a]:[e,a]}return t}function mergeDestinationQueryIntoUrl(e,t){const n=new URL(e.toString());const a=t.split("?")[1];if(!a){return n}const s=new URLSearchParams(a);for(const[e,t]of s.entries()){n.searchParams.set(e,t)}return n}function withResolvedInvocationTarget({result:e,url:t,resolvedPathname:n,invocationPathname:a}){const s=toResolvedQuery(t);return{...e,resolvedPathname:n,resolvedQuery:s,invocationTarget:{pathname:a,query:s}}}function matchDynamicRoute(e,t,n){const a=new RegExp(t.sourceRegex,n?"":"i");const s=e.match(a);if(!s){return{matched:false}}const r={};for(let e=1;e<s.length;e++){if(s[e]!==undefined){r[String(e)]=s[e]}}if(s.groups){Object.assign(r,s.groups)}return{matched:true,params:r,regexMatches:s}}function applyOnMatchHeaders(e,t,n,a,s){const r=new Headers(a);for(const a of e){const e=matchRoute(a,t,n,s);if(e.matched&&e.headers){for(const[t,n]of Object.entries(e.headers)){r.set(t,n)}}}return r}function checkDynamicRoutes(e,t,n,a,s,r,o,i,c,u,l,d=false,f){let h=t;if(l&&u){h=denormalizeNextDataUrl(t,o,i)}for(const t of e){const e=matchDynamicRoute(h.pathname,t,d);if(e.matched){const i=checkHasConditions(t.has,h,a);const u=checkMissingConditions(t.missing,h,a);if(i.matched&&u){const u=t.destination?replaceDestination(t.destination,e.regexMatches||null,i.captures):undefined;const l=u?u.split("?")[0]:h.pathname;const m=matchesPathnameWithLocaleFallback({pathname:l,pathnames:n,basePath:o,i18n:c});if(m&&(f===undefined||m===f)){const t=u?mergeDestinationQueryIntoUrl(h,u):h;const n=applyOnMatchHeaders(r,t,a,s,d);const o=withResolvedInvocationTarget({result:{routeMatches:e.params,resolvedHeaders:n},url:t,resolvedPathname:m,invocationPathname:h.pathname});return{matched:true,result:o,resetUrl:h}}}}}return{matched:false}}function resolveRewrittenPathname({url:e,routes:t,pathnames:n,requestHeaders:a,responseHeaders:s,basePath:r,buildId:o,i18n:i,shouldNormalizeNextData:c,isDataUrl:u,caseSensitive:l,status:d}){let f=e;if(u&&c){f=denormalizeNextDataUrl(e,r,o)}const h=matchesPathname(f.pathname,n);const m=h!==undefined&&!isDynamicTemplatePathname(h);const p=checkDynamicRoutes(t.dynamicRoutes,e,n,a,s,t.onMatch,r,o,i,c,u,l,m?h:undefined);if(p.matched&&p.result){return{...p.result,status:d}}if(h){const e=applyOnMatchHeaders(t.onMatch,f,a,s,l);return withResolvedInvocationTarget({result:{resolvedHeaders:e,status:d},url:f,resolvedPathname:h,invocationPathname:f.pathname})}return undefined}function shouldInvokeMiddlewareForRequest(e,t,n,a){const matchesMiddlewareMatchers=s=>{if(!e||e.length===0){return false}for(const r of e){const e=new RegExp(r.sourceRegex,a?"":"i");const o=s.match(e);if(!o){continue}const i=checkHasConditions(r.has,t,n);if(!i.matched){continue}const c=checkMissingConditions(r.missing,t,n);if(!c){continue}return true}return false};if(e===undefined){return true}if(e.length===0){return false}if(matchesMiddlewareMatchers(t.pathname)){return true}let s=t.pathname;try{s=decodeURIComponent(t.pathname)}catch{return false}if(s===t.pathname){return false}return matchesMiddlewareMatchers(s)}async function resolveRoutes(e){const{url:t,basePath:n,requestBody:a,headers:s,pathnames:r,routes:o,invokeMiddleware:i,buildId:c,i18n:u}=e;const{shouldNormalizeNextData:l,caseSensitive:d=false}=o;let f=new URL(t.toString());let h=new Headers(s);let m=new Headers;let p;let g;let w;const R=t.origin;let L=false;if(l){const e=`${n}/_next/data/${c}/`;L=t.pathname.startsWith(e);if(L){f=normalizeNextDataUrl(f,n,c)}}if(u&&!L){const e=f.pathname.startsWith(n)?f.pathname.slice(n.length)||"/":f.pathname;if(!e.startsWith("/_next/")&&!e.startsWith("/api/")){const t=f.hostname;const a=h.get("cookie")||undefined;const s=h.get("accept-language")||undefined;const r=normalizeLocalePath(e,u.locales);const o=!!r.detectedLocale;const i=detectDomainLocale(u.domains,t);const c=i?.defaultLocale||u.defaultLocale;let l=r.detectedLocale||c;const d=u.localeDetection!==false&&!o&&r.pathname==="/";if(d){const r=detectLocale({pathname:e,hostname:t,cookieHeader:a,acceptLanguageHeader:s,i18n:u});l=r.locale;if(l!==c){const a=detectDomainLocale(u.domains,undefined,l);if(a&&a.domain!==t){const t=a.http?"http":"https";const s=l===a.defaultLocale?"":`/${l}`;const r=new URL(`${t}://${a.domain}${n}${s}${e}${f.search}`);g={url:r,status:307}}if(!a||a&&a.domain===t){const t=new URL(f.toString());t.pathname=`${n}/${l}${e}`;g={url:t,status:307}}}}if(!o&&!g){const t=l||i?.defaultLocale||u.defaultLocale;f.pathname=`${n}/${t}${e}`}}}const y=processRoutes(o.beforeMiddleware,f,h,m,R,d);if(y.status){p=y.status}if(y.redirect){return{redirect:y.redirect,resolvedHeaders:m,status:p}}if(y.externalRewrite){return{externalRewrite:y.externalRewrite,resolvedHeaders:m,status:p}}if(y.stopped){w={status:p}}f=y.url;let v=f;if(L&&l){v=denormalizeNextDataUrl(f,n,c)}const x=shouldInvokeMiddlewareForRequest(o.middlewareMatchers,f,h,d);if(x){const e=await i({url:v,headers:h,requestBody:a});if(e.bodySent){return{middlewareResponded:true}}if(e.requestHeaders){h=new Headers(e.requestHeaders)}if(e.responseHeaders){e.responseHeaders.forEach(((e,t)=>{if(t.toLowerCase()==="set-cookie"){m.append(t,e)}else{m.set(t,e)}}))}if(e.redirect){if(!m.has("location")){m.set("Location",e.redirect.url.toString())}return{resolvedHeaders:m,status:e.redirect.status}}if(e.rewrite){f=e.rewrite;if(f.origin!==R){return{externalRewrite:f,resolvedHeaders:m,status:p}}}}if(g){if(!m.has("location")){m.set("location",g.url.toString())}return{redirect:g,resolvedHeaders:m}}if(w){return{resolvedHeaders:m,status:w.status}}if(L&&l){f=normalizeNextDataUrl(f,n,c)}const D=processRoutes(o.beforeFiles,f,h,m,R,d);if(D.status){p=D.status}if(D.redirect){return{redirect:D.redirect,resolvedHeaders:m,status:p}}if(D.externalRewrite){return{externalRewrite:D.externalRewrite,resolvedHeaders:m,status:p}}if(D.stopped){return{resolvedHeaders:m,status:p}}f=D.url;if(L&&l){f=denormalizeNextDataUrl(f,n,c)}let H=matchesPathname(f.pathname,r);if(H){for(const e of o.dynamicRoutes){const t=matchDynamicRoute(f.pathname,e,d);if(!t.matched){continue}const a=checkHasConditions(e.has,f,h);const s=checkMissingConditions(e.missing,f,h);if(!a.matched||!s){continue}const i=e.destination?replaceDestination(e.destination,t.regexMatches||null,a.captures):undefined;const c=i?i.split("?")[0]:f.pathname;const l=matchesPathnameWithLocaleFallback({pathname:c,pathnames:r,basePath:n,i18n:u});if(!l){if(isDynamicTemplatePathname(c)){continue}const e=i?mergeDestinationQueryIntoUrl(f,i):f;const n=applyOnMatchHeaders(o.onMatch,e,h,m,d);return withResolvedInvocationTarget({result:{routeMatches:t.params,resolvedHeaders:n,status:p},url:e,resolvedPathname:H,invocationPathname:f.pathname})}const g=l===H||isDynamicTemplatePathname(H);if(!g){continue}const w=i?mergeDestinationQueryIntoUrl(f,i):f;const R=applyOnMatchHeaders(o.onMatch,w,h,m,d);return withResolvedInvocationTarget({result:{routeMatches:t.params,resolvedHeaders:R,status:p},url:w,resolvedPathname:l,invocationPathname:f.pathname})}const e=applyOnMatchHeaders(o.onMatch,f,h,m,d);return withResolvedInvocationTarget({result:{resolvedHeaders:e,status:p},url:f,resolvedPathname:H,invocationPathname:f.pathname})}if(L&&l){f=normalizeNextDataUrl(f,n,c)}for(const e of o.afterFiles){const t=matchRoute(e,f,h,d);if(t.matched){if(t.headers){for(const[e,n]of Object.entries(t.headers)){m.set(e,n)}}if(e.status){p=e.status}if(t.destination){if(isRedirectStatus(e.status)&&t.headers&&hasRedirectHeaders(t.headers)){const n=isExternalDestination(t.destination)?new URL(t.destination):applyDestination(f,t.destination);return{redirect:{url:n,status:e.status},resolvedHeaders:m,status:p}}if(isExternalDestination(t.destination)){return{externalRewrite:new URL(t.destination),resolvedHeaders:m,status:p}}f=applyDestination(f,t.destination);if(f.origin!==R){return{externalRewrite:f,resolvedHeaders:m,status:p}}const a=resolveRewrittenPathname({url:f,routes:o,pathnames:r,requestHeaders:h,responseHeaders:m,basePath:n,buildId:c,i18n:u,shouldNormalizeNextData:l,isDataUrl:L,caseSensitive:d,status:p});if(a){return a}}}}for(const e of o.dynamicRoutes){const t=matchDynamicRoute(f.pathname,e,d);if(t.matched){const a=checkHasConditions(e.has,f,h);const s=checkMissingConditions(e.missing,f,h);if(a.matched&&s){const s=e.destination?replaceDestination(e.destination,t.regexMatches||null,a.captures):undefined;const i=s?s.split("?")[0]:f.pathname;H=matchesPathnameWithLocaleFallback({pathname:i,pathnames:r,basePath:n,i18n:u});if(H){const e=s?mergeDestinationQueryIntoUrl(f,s):f;const n=applyOnMatchHeaders(o.onMatch,e,h,m,d);return withResolvedInvocationTarget({result:{routeMatches:t.params,resolvedHeaders:n,status:p},url:e,resolvedPathname:H,invocationPathname:f.pathname})}}}}for(const e of o.fallback){const t=matchRoute(e,f,h,d);if(t.matched){if(t.headers){for(const[e,n]of Object.entries(t.headers)){m.set(e,n)}}if(e.status){p=e.status}if(t.destination){if(isRedirectStatus(e.status)&&t.headers&&hasRedirectHeaders(t.headers)){const n=isExternalDestination(t.destination)?new URL(t.destination):applyDestination(f,t.destination);return{redirect:{url:n,status:e.status},resolvedHeaders:m,status:p}}if(isExternalDestination(t.destination)){return{externalRewrite:new URL(t.destination),resolvedHeaders:m,status:p}}f=applyDestination(f,t.destination);if(f.origin!==R){return{externalRewrite:f,resolvedHeaders:m,status:p}}const a=resolveRewrittenPathname({url:f,routes:o,pathnames:r,requestHeaders:h,responseHeaders:m,basePath:n,buildId:c,i18n:u,shouldNormalizeNextData:l,isDataUrl:L,caseSensitive:d,status:p});if(a){return a}}}}return{resolvedHeaders:m,status:p}}function responseToMiddlewareResult(e,t,a){const s={};const r={};e.headers.forEach(((e,t)=>{if(r[t]){const n=r[t];if(Array.isArray(n)){n.push(e)}else{r[t]=[n,e]}}else{r[t]=e}}));if(r["x-middleware-override-headers"]){const e=new Set;let n=r["x-middleware-override-headers"];if(typeof n==="string"){n=n.split(",")}for(const t of n){e.add(t.trim())}delete r["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=r[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 r[e]}}if(!r["x-middleware-rewrite"]&&!r["x-middleware-next"]&&!r["location"]){r["x-middleware-refresh"]="1"}delete r["x-middleware-next"];const o=new Headers;for(const[e,n]of Object.entries(r)){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)}}}s.responseHeaders=o;s.requestHeaders=t;if(r["x-middleware-rewrite"]){const e=r["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){s.rewrite=e;return s}s.rewrite=e}catch{s.rewrite=new URL(t,a)}}if(r["location"]){const t=r["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);s.redirect={url:t,status:e.status};return s}catch{s.redirect={url:new URL(n,a),status:e.status};return s}}else{o.set("location",t);return s}}if(r["x-middleware-refresh"]){s.bodySent=true;return s}return s}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})();
package/license.md ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Vercel, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@next/routing",
3
- "version": "16.5.0-canary.6",
3
+ "version": "16.5.0-canary.60",
4
4
  "keywords": [
5
5
  "react",
6
6
  "next",