1 line
14 KiB
JavaScript
1 line
14 KiB
JavaScript
|
|
(function(){"use strict";var e={993:function(e,t,r){var n=Object.defineProperty;var o=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var i=Object.prototype.hasOwnProperty;var __export=(e,t)=>{for(var r in t)n(e,r,{get:t[r],enumerable:true})};var __copyProps=(e,t,r,c)=>{if(t&&typeof t==="object"||typeof t==="function"){for(let s of a(t))if(!i.call(e,s)&&s!==r)n(e,s,{get:()=>t[s],enumerable:!(c=o(t,s))||c.enumerable})}return e};var __toCommonJS=e=>__copyProps(n({},"__esModule",{value:true}),e);var c={};__export(c,{collectHasSegments:()=>collectHasSegments,convertCleanUrls:()=>convertCleanUrls,convertHeaders:()=>convertHeaders,convertRedirects:()=>convertRedirects,convertRewrites:()=>convertRewrites,convertTrailingSlash:()=>convertTrailingSlash,getCleanUrls:()=>getCleanUrls,pathToRegexp:()=>pathToRegexp,sourceToRegex:()=>sourceToRegex});e.exports=__toCommonJS(c);var s=r(310);var f=r(671);var u=r(397);function cloneKeys(e){if(typeof e==="undefined"){return void 0}return e.slice(0)}function compareKeys(e,t){const r=typeof e==="undefined"?"undefined":e.toString();const n=typeof t==="undefined"?"undefined":t.toString();return r===n}function pathToRegexp(e,t,r,n){const o=cloneKeys(r);const a=(0,f.pathToRegexp)(t,r,n);try{const i=r;const c=(0,u.pathToRegexp)(t,o,n);const s=a.toString()!==c.toString();if(process.env.FORCE_PATH_TO_REGEXP_LOG||s){const r=JSON.stringify({path:t,currentRegExp:a.toString(),newRegExp:c.toString()});console.error(`[vc] PATH TO REGEXP PATH DIFF @ #${e}: ${r}`)}const f=!compareKeys(r,o);if(process.env.FORCE_PATH_TO_REGEXP_LOG||f){const t=JSON.stringify({isDiffKeys:f,currentKeys:i,newKeys:o});console.error(`[vc] PATH TO REGEXP KEYS DIFF @ #${e}: ${t}`)}}catch(r){const n=r;const o=JSON.stringify({path:t,error:n.message});console.error(`[vc] PATH TO REGEXP ERROR @ #${e}: ${o}`)}return a}const p="__UN_NAMED_SEGMENT__";function getCleanUrls(e){const t=e.map(toRoute).filter((e=>e.endsWith(".html"))).map((e=>({html:e,clean:e.slice(0,-5)})));return t}function convertCleanUrls(e,t,r=308){const n=[];if(e){const e=t?"/$1/":"/$1";n.push({src:"^/(?:(.+)/)?index(?:\\.html)?/?$",headers:{Location:e},status:r});n.push({src:"^/(.*)\\.html/?$",headers:{Location:e},status:r})}return n}function convertRedirects(e,t=308){return e.map((e=>{const{src:r,segments:n}=sourceToRegex(e.source);const o=collectHasSegments(e.has);normalizeHasKeys(e.has);normalizeHasKeys(e.missing);try{const a=replaceSegments(n,o,e.destination,true);let i;if(typeof e.permanent==="boolean"){i=e.permanent?308:307}else if(e.statusCode){i=e.statusCode}else{i=t}const c={src:r,headers:{Location:a},status:i};if(e.has){c.has=e.has}if(e.missing){c.missing=e.missing}return c}catch(t){throw new Error(`Failed to parse redirect: ${JSON.stringify(e)}`)}}))}function convertRewrites(e,t){return e.map((e=>{const{src:r,segments:n}=sourceToRegex(e.source);const o=collectHasSegments(e.has);normalizeHasKeys(e.has);normalizeHasKeys(e.missing);try{const a=replaceSegments(n,o,e.destination,false,t);const i={src:r,dest:a,check:true};if(e.has){i.has=e.has}if(e.missing){i.missing=e.missing}if(e.statusCode){i.status=e.statusCode}return i}catch(t){throw new Error(`Failed to parse rewrite: ${JSON.stringify(e)}`)}}))}function convertHeaders(e){return e.map((e=>{const t={};const{src:r,segments:n}=sourceToRegex(e.source);const o=collectHasSegments(e.has);normalizeHasKeys(e.has);normalizeHasKeys(e.missing);const a=n.filter((e=>e!==p));const i={};n.forEach(((e,t)=>{i[e]=toSegmentDest(t)}));o.forEach((e=>{i[e]="$"+e}));e.headers.forEach((({key:e,value:r})=>{if(a.length>0||o.length>0){if(e.includes(":")){e=safelyCompile(e,i)}if(r.includes(":")){r=safelyCompile(r,i)}}t[e]=r}));const c={src:r,headers:t,continue:true};if(e.has){c.has=e.has}if(e.missing){c.missing=e.missing}return c}))}function convertTrailingSlash(e,t=308){const r=[];if(e){r.push({src:"^/\\.well-known(?:/.*)?$"});r.push({src:"^/((?:[^/]+/)*[^/\\.]+)$",headers:{Location:"/$1/"},status:t});r.push({src:"^/((?:[^/]+/)*[^/]+\\.\\w+)/$",headers:{Location:"/$1"},status:t})}else{r.push({src:"^/(.*)\\/$",headers:{Loca
|