web-listener 0.9.0 → 0.11.0
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/index.d.ts +28 -20
- package/index.js +1 -1
- package/package.json +1 -1
- package/run.js +1 -1
- package/schema.json +1 -1
package/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { FileHandle } from 'node:fs/promises';
|
|
|
6
6
|
import { ReadableStream, TransformStream, TextDecoderOptions } from 'node:stream/web';
|
|
7
7
|
import { AgentOptions, Agent as Agent$1 } from 'node:https';
|
|
8
8
|
|
|
9
|
-
type ClientErrorListener = (
|
|
9
|
+
type ClientErrorListener = (error: Error, socket: Duplex) => void;
|
|
10
10
|
type UpgradeListener = (req: IncomingMessage, socket: Duplex, head: Buffer) => void;
|
|
11
11
|
type ShouldUpgradeCallback = (req: IncomingMessage) => boolean;
|
|
12
12
|
|
|
@@ -45,8 +45,8 @@ declare class Queue<T> {
|
|
|
45
45
|
|
|
46
46
|
type MaybePromise<T> = Promise<T> | T;
|
|
47
47
|
|
|
48
|
-
type ServerErrorCallback = (error: unknown,
|
|
49
|
-
type UpgradeErrorHandler = (error: unknown
|
|
48
|
+
type ServerErrorCallback = (error: unknown, context: string, req: IncomingMessage) => void;
|
|
49
|
+
type UpgradeErrorHandler = (error: unknown) => void;
|
|
50
50
|
|
|
51
51
|
type SoftCloseHandler = (reason: string) => MaybePromise<void>;
|
|
52
52
|
declare function setSoftCloseHandler(req: IncomingMessage, fn: SoftCloseHandler): void;
|
|
@@ -55,13 +55,13 @@ declare const defer: (req: IncomingMessage, fn: () => MaybePromise<void>) => voi
|
|
|
55
55
|
declare const addTeardown: (req: IncomingMessage, fn: () => MaybePromise<void>) => void;
|
|
56
56
|
declare const getAbortSignal: (req: IncomingMessage) => AbortSignal;
|
|
57
57
|
|
|
58
|
-
type AcceptUpgradeHandler<T> = (
|
|
58
|
+
type AcceptUpgradeHandler<T, Req = {}> = (req: IncomingMessage & Req, socket: Duplex, head: Buffer) => Promise<AcceptUpgradeResult<T>>;
|
|
59
59
|
interface AcceptUpgradeResult<T> {
|
|
60
60
|
return: T;
|
|
61
|
-
onError
|
|
62
|
-
softCloseHandler
|
|
61
|
+
onError?: UpgradeErrorHandler;
|
|
62
|
+
softCloseHandler?: SoftCloseHandler;
|
|
63
63
|
}
|
|
64
|
-
declare function acceptUpgrade<T>(req: IncomingMessage, upgrade: AcceptUpgradeHandler<T>): Promise<T>;
|
|
64
|
+
declare function acceptUpgrade<T, Req = {}>(req: IncomingMessage & Req, upgrade: AcceptUpgradeHandler<T, Req>): Promise<T>;
|
|
65
65
|
|
|
66
66
|
declare class RoutingInstruction extends Error {
|
|
67
67
|
}
|
|
@@ -126,7 +126,7 @@ interface NativeListenersOptions {
|
|
|
126
126
|
*/
|
|
127
127
|
socketCloseTimeout?: number;
|
|
128
128
|
}
|
|
129
|
-
type ServerGeneralErrorCallback = (error: unknown,
|
|
129
|
+
type ServerGeneralErrorCallback = (error: unknown, context: string, req: IncomingMessage | undefined) => void;
|
|
130
130
|
interface NativeListeners {
|
|
131
131
|
request: RequestListener;
|
|
132
132
|
upgrade: UpgradeListener;
|
|
@@ -195,9 +195,9 @@ declare class WebListener extends WebListener_base {
|
|
|
195
195
|
listen(port: number, host: string, options?: CombinedServerOptions): Promise<AugmentedServer>;
|
|
196
196
|
}
|
|
197
197
|
interface RequestErrorDetail {
|
|
198
|
-
error: unknown;
|
|
199
198
|
server: Server;
|
|
200
|
-
|
|
199
|
+
error: unknown;
|
|
200
|
+
context: string;
|
|
201
201
|
request: IncomingMessage | undefined;
|
|
202
202
|
}
|
|
203
203
|
interface AugmentedServer extends Server {
|
|
@@ -565,7 +565,7 @@ interface CompressionInfo {
|
|
|
565
565
|
declare function compressFileOffline(file: string, options: FileNegotiationOption[], minCompress: number): Promise<CompressionInfo>;
|
|
566
566
|
declare function compressFilesInDir(dir: string, options: FileNegotiationOption[], minCompress: number): Promise<CompressionInfo[]>;
|
|
567
567
|
|
|
568
|
-
declare const emitError: (req: IncomingMessage, error: unknown) => void;
|
|
568
|
+
declare const emitError: (req: IncomingMessage, error: unknown, context?: string) => void;
|
|
569
569
|
|
|
570
570
|
interface JSONErrorHandlerOptions {
|
|
571
571
|
/**
|
|
@@ -709,7 +709,8 @@ interface FileFinderOptions {
|
|
|
709
709
|
negotiation?: FileNegotiation[] | undefined;
|
|
710
710
|
}
|
|
711
711
|
interface FileFinderCore {
|
|
712
|
-
find(pathParts: string[], negotiation?: NegotiationInput): Promise<ResolvedFileInfo | null>;
|
|
712
|
+
find(pathParts: string[], negotiation?: NegotiationInput, warnings?: string[] | undefined): Promise<ResolvedFileInfo | null>;
|
|
713
|
+
debugAllPaths(): Promise<Set<string>>;
|
|
713
714
|
readonly vary: string;
|
|
714
715
|
}
|
|
715
716
|
declare class FileFinder implements FileFinderCore {
|
|
@@ -724,7 +725,8 @@ declare class FileFinder implements FileFinderCore {
|
|
|
724
725
|
* @param negotiation any client-sent negotiation options to apply
|
|
725
726
|
* @returns details about the resolved file (including an active `FileHandle`), or `null`
|
|
726
727
|
*/
|
|
727
|
-
find(pathParts: string[], negotiation?: NegotiationInput): Promise<ResolvedFileInfo | null>;
|
|
728
|
+
find(pathParts: string[], negotiation?: NegotiationInput, warnings?: string[] | undefined): Promise<ResolvedFileInfo | null>;
|
|
729
|
+
debugAllPaths(): Promise<Set<string>>;
|
|
728
730
|
precompute(): Promise<FileFinderCore>;
|
|
729
731
|
}
|
|
730
732
|
interface ResolvedFileInfo extends NegotiationOutputInfo {
|
|
@@ -1160,6 +1162,13 @@ interface FileServerOptions extends FileFinderOptions {
|
|
|
1160
1162
|
* Compression, cache control, and range requests will continue to work as usual.
|
|
1161
1163
|
*/
|
|
1162
1164
|
fallback?: FallbackOptions | undefined;
|
|
1165
|
+
/**
|
|
1166
|
+
* Enable verbose error messages when a file is not found.
|
|
1167
|
+
* When this is false, only failures to find the fallback file will include verbose details.
|
|
1168
|
+
*
|
|
1169
|
+
* @default false
|
|
1170
|
+
*/
|
|
1171
|
+
verbose?: boolean;
|
|
1163
1172
|
/**
|
|
1164
1173
|
* A function to call when a file is being served. Can modify headers in the response.
|
|
1165
1174
|
* The default implementation is:
|
|
@@ -1203,7 +1212,7 @@ interface FallbackOptions {
|
|
|
1203
1212
|
* @param options custom configuration to apply
|
|
1204
1213
|
* @returns a promise of a server handler function (note this should be `await`ed before being used as a handler!)
|
|
1205
1214
|
*/
|
|
1206
|
-
declare const fileServer: (basePath: string, { mode, fallback, callback, ...options }?: FileServerOptions) => Promise<RequestHandler>;
|
|
1215
|
+
declare const fileServer: (basePath: string, { mode, fallback, verbose, callback, ...options }?: FileServerOptions) => Promise<RequestHandler>;
|
|
1207
1216
|
declare function setDefaultCacheHeaders(req: IncomingMessage, res: ServerResponse, file: ResolvedFileInfo): void;
|
|
1208
1217
|
|
|
1209
1218
|
interface InternalWebSocketServerOptions {
|
|
@@ -1219,14 +1228,13 @@ declare class WebSocketServer<T, Options> {
|
|
|
1219
1228
|
off(event: 'wsClientError', handler: (error: Error) => void): void;
|
|
1220
1229
|
}
|
|
1221
1230
|
interface ClosableWebSocket {
|
|
1222
|
-
close(status: number, message
|
|
1223
|
-
}
|
|
1224
|
-
interface WebSocketOptions {
|
|
1225
|
-
softCloseStatusCode?: number | undefined;
|
|
1231
|
+
close(status: number, message: string): void;
|
|
1226
1232
|
}
|
|
1227
|
-
|
|
1233
|
+
type MakeAcceptWebSocketOptions<T, PassThroughOptions> = Partial<PassThroughOptions & Record<ForbiddenWebSocketServerOptions, never>> & {
|
|
1228
1234
|
WebSocket?: (new (...args: any) => T) | undefined;
|
|
1229
|
-
|
|
1235
|
+
softCloseStatusCode?: number | undefined;
|
|
1236
|
+
};
|
|
1237
|
+
declare function makeAcceptWebSocket<T extends ClosableWebSocket, PassThroughOptions>(wsServerClass: typeof WebSocketServer<T, InternalWebSocketServerOptions & PassThroughOptions>, { softCloseStatusCode, ...options }?: MakeAcceptWebSocketOptions<T, PassThroughOptions>): (req: IncomingMessage) => Promise<T>;
|
|
1230
1238
|
|
|
1231
1239
|
type MessageHandler = ((data: string | Buffer) => void) & ((data: Buffer, isBinary: boolean) => void);
|
|
1232
1240
|
type CloseHandler = () => void;
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isIPv4 as t,isIPv6 as e}from"node:net";import{STATUS_CODES as n,createServer as i,Agent as r,request as o,ServerResponse as s}from"node:http";import{createReadStream as c,constants as a,createWriteStream as f,openAsBlob as u}from"node:fs";import{createHash as h,randomUUID as l}from"node:crypto";import{pipeline as d}from"node:stream/promises";import w from"node:zlib";import{promisify as p}from"node:util";import{extname as m,join as y,dirname as g,basename as b,sep as v,resolve as E}from"node:path";import{readFile as _,writeFile as T,stat as x,readdir as S,realpath as k,open as $,mkdtemp as A,rm as N}from"node:fs/promises";import{tmpdir as O,platform as R}from"node:os";import{Agent as P,request as F}from"node:https";import{TransformStream as C,TextDecoderStream as U,DecompressionStream as M,ReadableStream as D}from"node:stream/web";import{Readable as I,Duplex as B,Writable as j}from"node:stream";function H(n){if(!n||"unknown"===n)return;const i=/^((?:\d{1,3}\.){3}\d{1,3})(?::(\d+))?$/.exec(n);if(i?.[1]&&t(i[1]))return{type:"IPv4",ip:i[1],port:i[2]?Number.parseInt(i[2]):void 0};const r=/^\[([\da-fA-F:]+)\](?::(\d+))?$|^([\da-fA-F:]+)$/.exec(n);if(r?.[1]&&e(r[1]))return{type:"IPv6",ip:r[1].toLowerCase(),port:r[2]?Number.parseInt(r[2]):void 0};if(r?.[3]&&e(r[3]))return{type:"IPv6",ip:r[3].toLowerCase(),port:void 0};const o=/^(.*?):(\d+)$/i.exec(n);return o?.[2]?{type:"alias",ip:o[1],port:Number.parseInt(o[2])}:{type:"alias",ip:n,port:void 0}}function q(t){const e=new Set,n=[],i=[];for(const r of t){const t=/^((?:\d{1,3}\.){3}\d{1,3})(?:\/(\d+))?$/.exec(r);if(t?.[1]){const e=t[2]?Number.parseInt(t[2]):32,i=e<32?4294967295>>>e:0;n.push([z(t[1])|i,i]);continue}const o=/^\[?([\da-fA-F:]+)\]?(?:\/(\d+))?$/.exec(r);if(o?.[1]){const t=W(o[1]),e=o[2]?L>>BigInt(Number.parseInt(o[2])):0n;i.push([t|e,e]);continue}e.add(r)}return t=>{switch(t?.type){case"alias":return e.has(t.ip);case"IPv4":const r=z(t.ip);return n.some(([t,e])=>(r|e)===t);case"IPv6":const o=W(t.ip);return i.some(([t,e])=>(o|e)===t);default:return!1}}}const L=/*@__PURE__*/BigInt("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");function z(t){const e=t.split(".").map(Number);return(e[0]<<24|e[1]<<16|e[2]<<8|e[3])>>>0}function W(t){const e=t.split(":").map(t=>t?Number.parseInt(t,16):-1);let n=0n;for(const t of e)t<0?n<<=16n*BigInt(9-e.length):n=n<<16n|BigInt(t);return n}class G{constructor(t){const e={t:null,i:null};this.o=e,this.u=e,void 0!==t&&this.push(t)}isEmpty(){return!this.o.i}clear(){this.o.i=null,this.o.t=null,this.u=this.o}push(t){const e={t,i:null};this.u.i=e,this.u=e}shift(){if(!this.o.i)return null;this.o=this.o.i;const t=this.o.t;return this.o.t=null,t}remove(t){for(let e=this.o;e.i;e=e.i)if(e.i.t===t){e.i=e.i.i;break}}[Symbol.iterator](){return{next:()=>{if(!this.o.i)return{value:null,done:!0};this.o=this.o.i;const t=this.o.t;return this.o.t=null,{value:t,done:!1}}}}}class J{constructor(){this.h=new G,this.l=new G,this.m=0}push(t){if(this.m)return;const e=this.l.shift();e?(e.v&&clearTimeout(e.v),e._(t)):this.h.push(t)}shift(t){return this.h.isEmpty()?this.m?Promise.reject(this.T):new Promise((e,n)=>{const i={_:e,S:n,v:null};this.l.push(i),void 0!==t&&(i.v=setTimeout(()=>{this.l.remove(i),n(new Error(`timeout after ${t}ms`))},t))}):Promise.resolve(this.h.shift())}k(t){this.T=t;for(const e of this.l)e.S(t),e.v&&clearTimeout(e.v)}close(t){this.m||(this.m=1,this.k(t))}fail(t){this.m||(this.m=2,this.k(t))}[Symbol.asyncIterator](){return{next:()=>this.shift().then(t=>({value:t,done:!1}),t=>{if(2===this.m)throw t;return{value:null,done:!0}})}}}function V(t,e){if(t instanceof e)return t;if(t&&"object"==typeof t){if("cause"in t)return V(t.cause,e);if("error"in t)return V(t.error,e)}}function Z(t,e="http"){if(!t)throw new TypeError("no address");if("string"==typeof t)return t;if("IPv4"===t.family)return`${e}://${t.address}:${t.port}`;if("IPv6"===t.family)return`${e}://[${t.address}]:${t.port}`;throw new TypeError(`unknown address family: ${t.family}`)}const X=/*@__PURE__*/Buffer.alloc(0),Y=t=>new URL("http://localhost"+(t.url??"/"));class K extends Error{constructor(t,e,n){super(n??""),this.error=t,this.suppressed=e}}const Q=globalThis.SuppressedError??K;class tt{constructor(){this.$=!1}A(t){this.$?t!==this.N&&(this.N=new Q(t,this.N)):(this.N=t,this.$=!0)}O(){this.$=!1,this.N=void 0}}const et=new WeakMap;function nt(t,e,n){const i=et.get(t);if(i)return i;const r=Y(t),o={R:t,P:r,F:decodeURIComponent(r.pathname),C:new AbortController,U:e,M:[],D:[],I:n?ot(t):null};return et.set(t,o),o}function it(t,e,n){e||(t.I=null),t.B=n;const i=async()=>{t.C.abort(n.j.writableEnded?"complete":"client abort");const e=new tt;await rt(t.M,e,t),await rt(t.D,e,t,()=>{t.H=async e=>{try{await e()}catch(e){t.U(e,"tearing down",t.R)}}}),e.$&&t.U(e.N,"tearing down",t.R)};return n.j.closed?i():n.j.once("close",i),t}async function rt(t,e,n,i){for(;n.L;)await n.L;const r=(async()=>{for(;;){const n=t.pop();if(!n)return void i?.();try{await n()}catch(t){e.A(t)}}})().then(()=>{n.L===r&&(n.L=void 0)});n.L=r,await r}function ot(t){return new Set(t.headers.upgrade?.split(",").map(t=>t.trim().toLowerCase())??[])}const st=t=>et.get(t),ct=t=>et.delete(t);function at(t){const e=st(t);if(!e)throw new RangeError("unknown request");return e}function ft(t,e,n=ft){throw t.code=e,Error.captureStackTrace(t,n),t}class ut{constructor(t){this.W=t,this.G=Object.create(null),this.J=!1}get headersSent(){return this.J}writeHead(t,e=n[t]??"-"){return this.J&&ft(new Error("Cannot write headers after they are sent to the client"),"ERR_HTTP_HEADERS_SENT"),this.W.write([`HTTP/1.1 ${t} ${dt(e)}`,...ht(this.G),"",""].join("\r\n"),"ascii"),this.J=!0,this}write(t,e="utf-8",n){return this.W.write(t,e,n)}end(t,e="utf-8",n){return this.W.end(t,e,n),this}setHeader(t,e){const n=t.toLowerCase();return this.G[n]="string"==typeof e||"number"==typeof e?e:[...e],this}setHeaders(t){for(const[e,n]of t)this.setHeader(e,n);return this}}function ht(t){const e=[];for(const[n,i]of Object.entries(t)){const t=lt(i);t&&e.push(`${dt(n)}: ${dt(t)}`)}return e}const lt=t=>"string"==typeof t?t:"number"==typeof t?String(t):t?t.join(", "):"",dt=t=>t.replaceAll(/[^ \t!-~]/g,"");function wt(t,e){const n=st(t);n&&pt(n,e)}function pt(t,e){t.V=e;const n=t.Z;n&&queueMicrotask(()=>vt(e,n,t))}const mt=t=>Boolean(st(t)?.Z);function yt(t,e,n){if(!t.Z){if(t.B&&!t.I){const e=t.B.j;e.headersSent||e.hasHeader("connection")||e.setHeader("connection","close")}t.B?.j.once("close",()=>t.R.socket.destroy()),t.Z={X:e,U:n},vt(t.V,t.Z,t),bt(t)}}function gt(t){if(t.B){if(t.I){if(!t.Y&&t.B.j.writable){const e=new ut(t.B.j);e.setHeader("connection","close"),e.writeHead(503)}}else{const e=t.B.j;e.headersSent||(e.hasHeader("connection")||e.setHeader("connection","close"),e.writeHead(503))}t.B.j.end(()=>t.R.socket.destroy())}else t.R.socket.destroy()}function bt(t){if(clearTimeout(t.K),!t.tt||t.H)return;const e=Date.now();if(e>=t.tt)return void gt(t);let n=t.tt;t.et&&!t.Z&&(e<t.et.nt?n=t.et.nt:(t.Z=t.et,vt(t.V,t.Z,t))),void 0===t.K&&t.D.push(()=>clearTimeout(t.K)),t.K=setTimeout(()=>bt(t),n-e)}async function vt(t,e,n){try{await(t?.(e.X))}catch(t){e.U(t,"soft closing",n.R),gt(n)}}const Et=(t,e)=>{const n=at(t);n.H?n.H(e):n.M.push(e)},_t=(t,e)=>{const n=at(t);n.H?n.H(e):n.D.push(e)},Tt=t=>at(t).C.signal;class xt extends Error{}const St=new xt("STOP"),kt=new xt("CONTINUE"),$t=new xt("NEXT_ROUTE"),At=new xt("NEXT_ROUTER");async function Nt(t,e){const n=at(t);if(!n.B)throw new TypeError("cannot call acceptUpgrade from shouldUpgrade");if(!n.I)throw new TypeError("not an upgrade request");if(n.it)return n.rt;const i=n.B.j;if(!i.readable||!i.writable)throw St;n.Y=!0;const r=await e(t,i,n.B.o);return n.B.o=X,n.it=r.onError,pt(n,r.softCloseHandler),n.rt=r.return,r.return}const Ot=RegExp.escape??(t=>t.replaceAll(/[^a-zA-Z0-9_ ]/g,t=>"\\u"+t.charCodeAt(0).toString(16).padStart(4,"0"))),Rt=t=>t,Pt=t=>void 0===t?void 0:""===t?[]:t.split("/"),Ft=t=>void 0===t?void 0:""===t?[]:t.split("/").filter(t=>t);function Ct(t){const e={},n=new Map;for(const[i,r]of Object.entries(t))e[i]=!1,n.set(r,i);return t=>{const i={...e};for(let e=0;e<t.length;++e){const r=n.get(t[e]);if(!r)return[i,t.substring(e)];i[r]=!0}return[i,""]}}const Ut=/*@__PURE__*/Ct({ot:"i",st:"!"}),Mt=Object.freeze({});function Dt(t,e,n){const i=t.R.url,r=t.F,o=t.ct??Mt;return t.R.url=encodeURIComponent(e).replaceAll(/%2F/g,"/")+t.P.search,t.F=e,n.length>0&&(t.ct=Object.freeze(Object.fromEntries([...Object.entries(o),...n]))),()=>{t.R.url=i,t.F=r,t.ct=o}}function It(t){return st(t)?.ct??Mt}function Bt(t,e){return It(t)[e]}function jt(t){const e=st(t);return e?e.P.pathname+e.P.search:t.url??"/"}function Ht(t){const e=st(t);e&&(t.url=e.P.pathname+e.P.search)}const qt=t=>"function"==typeof t?{handleRequest:t}:t,Lt=(t,e)=>"function"==typeof t?{handleUpgrade:t,shouldUpgrade:e}:{shouldUpgrade:e,...t},zt=(t,e=Xt)=>({handleRequest:t,handleUpgrade:t,shouldUpgrade:e}),Wt=t=>"function"==typeof t?{handleError:t}:t,Gt=(t,e)=>Jt(e=>e instanceof t,e),Jt=(t,e)=>({handleError:(n,i,r)=>{if(r.response&&t(n))return e(n,i,r.response);throw n},shouldHandleError:(e,n,i)=>Boolean(i.response)&&t(e)}),Vt=t=>"function"==typeof t?{handleRequest:t}:t,Zt=t=>"function"==typeof t?{handleUpgrade:t}:t,Xt=()=>!1,Yt=Symbol("http");class Kt{constructor(){this.ft=[],this.ut=[]}A(t,e,n,i,r){const o=n?((t,e)=>{const n=["^"],i=[],r=/[{}]|\/+|\\(.)|[:*]([a-zA-Z0-9_]*)/g,[{ot:o,st:s},c]=Ut(t);if("/"!==c[0])throw new TypeError("path must begin with '/' or flags");let a=0,f=0;for(const t of c.matchAll(r)){t.index>a&&n.push(Ot(c.substring(a,t.index)));const e=t[0];if("{"===e)n.push("(?:"),++f;else if("}"===e){if(0===f)throw new TypeError(`unbalanced optional braces in path at ${t.index}`);--f,n.push(")?")}else if("/"===e[0])n.push(e),s||n.push("+");else if("\\"===e[0])n.push(Ot(t[1]));else{const r=e[0],o=t[2];if(!o)throw new TypeError(`unnamed parameter or unescaped '${r}' at ${t.index}`);"*"===r?(n.push("(.*?)"),i.push({ht:o,lt:s?Pt:Ft})):(n.push("([^/]+?)"),i.push({ht:o,lt:Rt}))}a=t.index+e.length}if(a<c.length&&n.push(Ot(c.substring(a))),f>0)throw new TypeError("unbalanced optional braces in path");return e&&(n.push("(?:"),s?n.push("(?:(?<=/)|/)"):n.push("(?:/+|(?<=/))"),n.push("(?<rest>.*))?")),n.push("$"),{dt:new RegExp(n.join(""),o?"i":""),wt:i}})(n,i):{dt:null,wt:[]};return this.ft.push({yt:t,gt:"string"==typeof e?e.toLowerCase():e,bt:o.dt,vt:o.wt,Et:r}),this}use(...t){return this.A(null,null,null,!0,t.map(Vt))}mount(t,...e){return this.A(null,null,t,!0,e.map(Vt))}within(t,e){const n=new Kt;return e(n),this.mount(t,n)}at(t,...e){return this.A(null,null,t,!1,e.map(Vt))}onRequest(t,e,...n){return this.A(te(t),Yt,e,!1,n.map(Vt))}onUpgrade(t,e,n,...i){return this.A(te(t),e,n,!1,i.map(Zt))}onError(...t){return this.A(null,null,null,!0,t.map(Wt))}onReturn(...t){return this.ut.push(...t),this}on(t,...e){const n=/^([A-Z]+) (\/.*)$/.exec(t);if(!n)throw new TypeError("invalid method + path spec: "+JSON.stringify(t));return this.A(n[1],Yt,n[2],!1,e.map(Vt))}get=(t,...e)=>this.A(Qt,Yt,t,!1,e.map(Vt));delete=(...t)=>this.onRequest("DELETE",...t);getOnly=(...t)=>this.onRequest("GET",...t);head=(...t)=>this.onRequest("HEAD",...t);options=(...t)=>this.onRequest("OPTIONS",...t);patch=(...t)=>this.onRequest("PATCH",...t);post=(...t)=>this.onRequest("POST",...t);put=(...t)=>this.onRequest("PUT",...t);ws=(...t)=>this.onUpgrade("GET","websocket",...t);async handleRequest(t){return this._t(t,new tt)}async handleUpgrade(t){return this._t(t,new tt)}async handleError(t,e){const n=new tt;return n.A(t),this._t(e,n)}shouldUpgrade(t){return this.Tt(at(t))}Tt(t){for(const e of this.ft){const n=ee(t,e);if(!n)continue;let i=()=>{};if(!0!==n)try{i=Dt(t,n.xt,[])}catch{continue}try{for(const n of e.Et)if(re(n,t))return!0}finally{i()}}return!1}async _t(t,e){const n=at(t),i=await this.St(n,e);if(e.$)throw e.N;return i}async St(t,e){for(const n of this.ft){const i=ee(t,n);if(!i)continue;let r=()=>{};if(!0!==i)try{const e=i.kt();r=Dt(t,i.xt,e)}catch(t){e.A(t);continue}try{const i=await ne(t,n.Et,this.ut,e);if(i===At)break;if(i===$t)continue;return i}finally{r()}}return kt}}const Qt=new Set(["HEAD","GET"]),te=t=>t?"string"==typeof t?t:new Set(t):null;function ee(t,e){if("string"==typeof e.yt){if(e.yt!==t.R.method)return!1}else if(null!==e.yt&&!e.yt.has(t.R.method??""))return!1;if(e.gt===Yt){if(t.I)return!1}else if(null!==e.gt&&!t.I?.has(e.gt))return!1;if(null===e.bt)return!0;const n=e.bt.exec(t.F);return!!n&&{xt:"/"+(n.groups?.rest??""),kt:()=>e.vt.map((t,e)=>[t.ht,t.lt(n[e+1])])}}async function ne(t,e,n,i){for(const r of e){let e=await ie(r,t,i);if(e!==kt){if(!t.I&&!(e instanceof xt)&&n.length)try{const i="object"==typeof e?e:void 0,r=t.R,o=t.B.j;for(const t of n)await t(i,r,o)}catch(t){i.A(t);continue}return e}}return $t}async function ie(t,e,n){if(t instanceof Kt)return t.St(e,n);let i=kt;try{if(n.$){if(t.handleError){const r=n.N,o=e.I?{socket:e.B.j,head:e.B.o,hasUpgraded:e.Y??!1}:{response:e.B.j};t.shouldHandleError&&!t.shouldHandleError(r,e.R,o)||(n.O(),i=await t.handleError(r,e.R,o))}}else if(e.I){if(t.handleUpgrade){const n=e.B;i=await t.handleUpgrade(e.R,n.j,n.o)}}else t.handleRequest&&(i=await t.handleRequest(e.R,e.B.j))}catch(t){t instanceof xt?i=t:n.A(t)}finally{e.M.length&&await((t,e)=>rt(t.M,e,t))(e,n)}return i===St?void 0:i}function re(t,e){if(t instanceof Kt)return t.Tt(e);if(!t.shouldUpgrade)return Boolean(t.handleUpgrade);try{return t.shouldUpgrade(e.R)}catch(t){return e.U(t,"checking should upgrade",e.R),!1}}class oe extends Error{constructor(t,{message:e,statusMessage:i,headers:r,body:o,...s}={}){super(e??o,s),this.statusCode=0|t,this.statusMessage=i??n[this.statusCode]??"-",this.headers=(t=>{if(!t||t instanceof Headers||Array.isArray(t))return new Headers(t);const e=t instanceof Map?[...t.entries()]:Object.entries(t);return new Headers(e.map(([t,e])=>[t,lt(e)]).filter(([t,e])=>e))})(r),this.body=o??"",this.name=`HTTPError(${this.statusCode} ${this.statusMessage})`}}const se=(t,e,n)=>{const i=ce(n);if(!i)return;const r=V(t,oe)??new oe(500);i.setHeader("content-type","text/plain; charset=utf-8"),i.setHeaders(r.headers),i.setHeader("content-length",String(Buffer.byteLength(r.body,"utf-8"))),n.response||i.setHeader("connection","close"),i.writeHead(r.statusCode,r.statusMessage),i.end(r.body,"utf-8")};function ce(t){if(t.response){const e=t.response;return e.headersSent?void e.end():e}const e=t.socket;if(!t.hasUpgraded&&e.writable)return e.addListener("finish",()=>e.destroy()),new ut(e);e.destroy()}function ae(t,{onError:e=fe,socketCloseTimeout:n=500}={}){let i=0,r="",o=e;const s=[],c=new Set,a=()=>{const t=[...s];s.length=0;for(const e of t)e()},f=t=>{t&&(c.size?s.push(t):setImmediate(t))},u=t=>{c.add(t),t.D.push(()=>{c.delete(t),!c.size&&s.length&&setImmediate(a)})};return{request:async(n,s)=>{let c;try{c=nt(n,e,!1)}catch(t){return e(t,"parsing request",n),void se(new oe(400),0,{response:s})}if(it(c,!1,{j:s}),u(c),1===i)yt(c,r,o);else if(2===i)return gt(c),void ct(n);const a=new tt,f=await ie(t,c,a);a.$||f!==kt&&f!==$t&&f!==At||a.A(new oe(404)),a.$&&(e(a.N,"handling request",n),se(a.N,0,{response:s}),ct(n))},upgrade:async(s,c,a)=>{let f;c.once("finish",()=>{const t=setTimeout(()=>c.destroy(),n);c.once("close",()=>clearTimeout(t))});try{f=nt(s,e,!0)}catch(t){return e(t,"parsing upgrade",s),void se(new oe(400),0,{socket:c,hasUpgraded:!1})}if(it(f,!0,{j:c,o:a}),a=X,u(f),1===i)yt(f,r,o);else if(2===i)return gt(f),void ct(s);const h=new tt,l=await ie(t,f,h);h.$||l!==kt&&l!==$t&&l!==At||(console.warn(`Upgrade ${s.headers.upgrade} request for ${s.url} fell-through. This probably means you need to add shouldUpgrade to one of your upgrade handlers, or if this is intentional, explicitly reject the request (throw new HTTPError(404)) instead of using CONTINUE.`),h.A(new oe(404))),h.$&&(e(h.N,"handling upgrade",s),f.it?f.it(h.N,s,c):se(h.N,0,{socket:c,head:f.B?.o??X,hasUpgraded:f.Y??!1}),ct(s))},shouldUpgrade:n=>{try{const i=nt(n,e,!0);return re(t,i)}catch{return!1}},clientError:(t,n)=>{const i=n.$t,r=t.code;n.writable&&!i?.headersSent&&n.end(he.get(r)??le),n.destroy(t),"HPE_INVALID_EOF_STATE"===r||e(t,"initialising request")},softClose(t,e,n){if(i<1){i=1,r=t,o=e;for(const n of c)yt(n,t,e)}f(n)},hardClose(t){if(i<2){i=2;for(const t of c)gt(t)}f(t)},countConnections:()=>c.size}}const fe=(t,e,n)=>{(V(t,oe)?.statusCode??1)&&console.error("%s",`unhandled error while ${e} ${n?.url??"(no request information)"}:`,t)},ue=t=>Buffer.from(`HTTP/1.1 ${t} ${n[t]}\r\nConnection: close\r\n\r\n`),he=/*@__PURE__*/new Map([["HPE_HEADER_OVERFLOW",/*@__PURE__*/ue(431)],["HPE_CHUNK_EXTENSIONS_OVERFLOW",/*@__PURE__*/ue(413)],["ERR_HTTP_REQUEST_TIMEOUT",/*@__PURE__*/ue(408)]]),le=/*@__PURE__*/ue(400);class de extends EventTarget{constructor(t){super(),this.At=t}attach(t,e={}){const n=(e,n,i)=>{const r={error:e,server:t,action:n,request:i};this.dispatchEvent(new CustomEvent("error",{detail:r}))&&fe(e,n,i)},i=ae(this.At,{...e,onError:n});!1===e.autoContinue&&t.addListener("checkContinue",i.request),!1===e.rejectNonStandardExpect&&t.addListener("checkExpectation",i.request),t.addListener("request",i.request),t.addListener("upgrade",i.upgrade);const r=t.shouldUpgradeCallback??(()=>!1);!1!==e.overrideShouldUpgradeCallback&&(t.shouldUpgradeCallback=i.shouldUpgrade),t.addListener("clientError",i.clientError);let o=()=>{o=void 0,t.removeListener("checkContinue",i.request),t.removeListener("checkExpectation",i.request),t.removeListener("request",i.request),t.removeListener("upgrade",i.upgrade),t.shouldUpgradeCallback===i.shouldUpgrade&&(t.shouldUpgradeCallback=r),t.removeListener("clientError",i.clientError)};return(t="",e=-1,r=!1,s)=>{if(r||o?.(),e>0){const r=setTimeout(()=>{o?.(),i.hardClose()},e);i.softClose(t,n,()=>{o?.(),clearTimeout(r),s?.()})}else 0===e?(o?.(),i.hardClose(s)):(o?.(),s&&setImmediate(s));return i}}createServer(t={}){t.shouldUpgradeCallback&&(t={overrideShouldUpgradeCallback:!1,...t});const e=i(t),n=this.attach(e,t),r=Object.assign(e,{closeWithTimeout:(t,i)=>new Promise(r=>n(t,i,!0,()=>{e.close(()=>r()),e.closeAllConnections()}))});return r}listen(t,e,n={}){const i=this.createServer(n);return n.socketTimeout&&i.setTimeout(n.socketTimeout),new Promise((r,o)=>{i.once("error",o),i.listen(t,e,n.backlog??511,()=>{i.off("error",o),r(i)})})}}const we=t=>st(t)?.P??Y(t),pe=t=>we(t).search,me=t=>new URLSearchParams(we(t).searchParams),ye=(t,e)=>we(t).searchParams.get(e);function ge(t,e){const n=t.indexOf(e);return-1===n?[t]:[t.substring(0,n),t.substring(n+e.length)]}function be(t){const e=t.headers.authorization;if(!e)return;const[n,i]=ge(e," ");return void 0!==i?[n.trim().toLowerCase(),i.trim()]:void 0}function ve(t){const e=/^text\/.*;\s*charset=([^;]+)/i.exec(t.headers["content-type"]??"");return e?.[1]?.trim().toLowerCase()??void 0}function Ee(t){const e=t.headers["if-range"];return e&&"string"==typeof e?/^("|W\/")/.test(e)?{etag:[e]}:{modifiedSeconds:$e(e)}:{}}function _e(t,e,{maxRanges:n=10,maxNonSequential:i=2,maxWithOverlap:r=2}={}){const o=t.headers.range;if(!o||0===e)return;const[s,c]=ge(o,"=");if("bytes"!==s||!c)return;const a=new oe(416,{headers:{"content-range":`bytes */${e}`}}),f=t=>{const e=xe(t);if(void 0===e)throw a;return e},u=[];for(const t of c.split(",")){const[i,r]=ge(t.trim(),"-");if(void 0===r)throw a;let o;if(i)o={start:f(i),end:r?Math.min(f(r),e-1):e-1};else{if(!r)throw a;o={start:Math.max(e-f(r),0),end:e-1}}if(!(o.start>=e)){if(o.end<o.start||u.length>=n)throw a;u.push(o)}}if(!u.length)throw a;if(u.length>i)for(let t=0;t<u.length-1;++t)if(u[t].start>u[t+1].start)throw a;if(u.length>r)for(let t=1;t<u.length;++t){const e=u[t];for(let n=0;n<t;++n){const t=u[n];if(e.end>=t.start&&t.end>=e.start)throw a}}return{ranges:u,totalSize:e}}function Te(t){if(void 0!==t)return"number"==typeof t?[String(t)]:t.length?"string"==typeof t?t.split(",").map(t=>t.trim()):t.flatMap(t=>t.split(",").map(t=>t.trim())):[]}function xe(t){if(t&&/^\s*-?\d+\s*$/.test(t))return Number.parseInt(t,10)}function Se(t){if(t)return t.split(",").map(t=>{const[e,...n]=t.split(";"),i=new Map(n.map(t=>{const[e,n]=ge(t,"=");return[e.trim(),n?.trim()??""]})),r=e.trim(),o="*/*"===r||"*"===r?0:r.endsWith("/*")?1:2,s=Math.max(0,Math.min(1,Number.parseFloat(i.get("q")??"1")));return{name:r,specifiers:i,specificity:o,q:s}})}function ke(t){const e=new Map,n=/\s*([^=]+)=([^";]*?|"(?:[^\\"]|\\.)*")\s*(?:;|$)/y;for(;n.lastIndex<t.length;){const i=n.exec(t);if(!i)throw new oe(400,{body:"invalid HTTP key values"});const r=i[1].toLowerCase();let o=i[2];'"'===o[0]&&(o=o.substring(1,o.length-1).replaceAll(/\\(.)/g,(t,e)=>e)),e.set(r,o)}return e}function $e(t){if("string"!=typeof t)return;const e=Date.parse(t);return Number.isNaN(e)?void 0:e/1e3|0}const Ae=t=>"function"==typeof t?t:()=>t;class Ne{constructor(t=Ue){this.Nt=Ae(t)}set(t,e){Pe(t,this,e)}get(t){return Fe(t,this)}clear(t){Ce(t,this)}withValue(t){return zt(e=>(Pe(e,this,t),kt))}}const Oe=(t,...e)=>{const n={Nt:n=>t(n,...e)};return t=>Fe(t,n)};function Re(t){return t.Ot||(t.Ot=new Map),t.Ot}function Pe(t,e,n){Re(at(t)).set(e,n)}function Fe(t,e){const n=st(t);if(!n)return e.Nt(t);const i=Re(n);if(i.has(e))return i.get(e);const r=e.Nt(t);return i.set(e,r),r}function Ce(t,e){const n=st(t);n?.Ot?.delete(e)}const Ue=()=>{throw new Error("property has not been set")};function Me({realm:t,extractAndValidateToken:e,fallbackTokenFetcher:n,closeOnExpiry:i=!0,softCloseBufferTime:r=0,onSoftCloseError:o}){const s=Ae(t);return{handler:zt(async t=>{const c=Date.now(),a=await s(t),f={"www-authenticate":`Bearer realm="${a}"`},u=be(t),h="bearer"===u?.[0]?u[1]:await(n?.(t));if(!h)throw new oe(401,{headers:f,body:"no token provided"});let l;try{l=await e(h,a,t)}catch(t){throw new oe(401,{headers:f,body:"invalid token",cause:t})}if(!l)throw new oe(401,{headers:f,body:"invalid token"});if("object"==typeof l){if("nbf"in l&&"number"==typeof l.nbf&&c<1e3*l.nbf)throw new oe(401,{headers:f,body:"token not valid yet"});if("exp"in l&&"number"==typeof l.exp){const e=1e3*l.exp;if(c>=e-r)throw new oe(401,{headers:f,body:"token expired"});i&&((t,e,n,i=0,r)=>{const o=at(t),s=n-Math.max(i,0),c=o.tt??Number.POSITIVE_INFINITY,a=o.et?.nt??c;s>=a&&n>=c||(n<c&&(o.tt=n),s<a&&(o.et={nt:s,X:e,U:r??o.U}),bt(o))})(t,"token expired",e,r,o)}}return Be.set(t,{Rt:a,Pt:!0,Ft:l,Ct:je(l)}),kt}),getTokenData:t=>{const e=Be.get(t);if(!e.Pt)throw new TypeError("cannot use getTokenData in an unauthenticated endpoint");return e.Ft}}}const De=(t,e)=>Be.get(t).Ct.has(e),Ie=t=>zt(e=>{const n=Be.get(e);if(!n.Ct.has(t))throw new oe(403,{headers:{"www-authenticate":`Bearer realm="${n.Rt}", scope="${t}"`},body:`scope required: ${t}`});return kt}),Be=/*@__PURE__*/new Ne({Rt:"",Pt:!1,Ft:null,Ct:new Set});function je(t){if(!t||"object"!=typeof t||!("scopes"in t))return new Set;const{scopes:e}=t;return Array.isArray(e)?new Set(e):"string"==typeof e?new Set([e]):e&&"object"==typeof e?new Set(Object.entries(e).filter(([t,e])=>e).map(([t])=>t)):new Set}function He(t,e){const n=`${0|e.mtimeMs} ${e.size} ${t??""}`;return`W/"${h("sha256").update(n).digest("base64").substring(0,12)}"`}async function qe(t){const e=h("sha256");return"string"==typeof t?await d(c(t),e):await d(t.createReadStream({start:0,autoClose:!1}),e),`"sha256-${e.digest("base64")}"`}const Le=(t,e)=>new RegExp(t,(t.unicodeSets?"v":t.unicode?"u":"")+(t.ignoreCase||e?"i":"")),ze={mime:"accept",language:"accept-language",encoding:"accept-encoding"},We={zstd:"{file}.zst",br:"{file}.br",gzip:"{file}.gz",deflate:"{file}.deflate",identity:"{file}"},Ge=t=>{return{type:"encoding",options:(e=t,n=We,Array.isArray(e)?e.map(t=>[t,n[t]]):Object.entries(e)).map(([t,e])=>({match:t,file:e}))};var e,n};function Je(t,e=10){const n=t.map(t=>({Ut:t.type,Mt:t.options.map(t=>({Dt:t.file,It:"string"==typeof t.match?t.match.toLowerCase():Le(t.match,!0),Bt:t.as??("string"==typeof t.match?t.match:void 0)}))})).filter(t=>t.Mt.length>0);return{options(t,i){let r=e;const o={};return function*t(e,s){const c=n[s];if(!c)return--r,void(yield{filename:e,info:o});const a=new Set,f=(h=i[c.Ut],h?.length?1===h.length?h:[...h].sort(Ve):[]),u=[];var h;for(const t of c.Mt){const e=f.find(e=>"string"==typeof t.It?e.name.toLowerCase()===t.It:t.It.test(e.name));e&&u.push({...e,jt:t})}for(const n of u.sort(Ve)){const i=Ze(e,n.jt.Dt);if(!a.has(i)&&(a.add(i),o[c.Ut]=n.jt.Bt,yield*t(i,s+1),r<=0))return}o[c.Ut]=void 0,!a.has(e)&&r>0&&(yield*t(e,s+1))}(t,0)},vary:[...new Set(n.map(t=>ze[t.Ut]))].join(" ")}}const Ve=(t,e)=>e.q-t.q||e.specificity-t.specificity;function Ze(t,e){return e.replaceAll(/\{(?:file|base|ext)\}/g,e=>"{file}"===e?t:"{base}"===e?t.replace(/\.[^.]*$/,""):m(t))}const Xe=/*@__PURE__*/tn("bin=application/octet-stream;gz(ip),json,ogg,pdf,wasm,xml,y(a)ml,zip,zst(d)=application/{ext};aac,flac,mid(i),wav(e)=audio/{ext};mp3=audio/mpeg;oga,opus=audio/ogg;otf,ttf,woff,woff2=font/{ext};apng,avif,bmp,gif,heic,heif,jp(e)g,png,tif(f),webp=image/{ext};ico,cur=image/x-icon;svg=image/svg+xml;3mf,obj,stl,u3d=model/{ext};wrl=model/vrml;x3d=model/x3d+xml;x3db=model/x3d+binary;x3dv=model/x3d+vrml;css,csv,htm(l),rtf,vcard=text/{ext};(m)js=text/javascript;md=text/markdown;txt=text/plain;3gp(p),3g(pp)2,mp4,mp(e)g,h264=video/{ext};mov=video/quicktime;ogv=video/ogg");let Ye=/*@__PURE__*/new Map(Xe);function Ke(){Ye=new Map(Xe)}function Qe(t){const e=new Map;for(const n of t.split("\n")){const[t,...i]=n.replaceAll(/\s+/g," ").trim().split(" ");if(!t.startsWith("#"))for(const n of i)e.set(n.toLowerCase(),t)}return e}function tn(t){const e=new Map;for(const n of t.split(/[\n;]/g)){const[t,i,r]=/^ *([^=]+)=(.*)$/.exec(n)??[null,null,""];for(const t of i?.split(",")??[]){const[n,i,o="",s=""]=/^([^(]*)(?:\(([^)]*)\)(.*))?$/.exec(t),c=i+o+s,a=r.replace("{ext}",c);e.set(c.toLowerCase(),a),o&&e.set((i+s).toLowerCase(),a)}}return e}function en(t){for(const[e,n]of t)Ye.set(e.toLowerCase(),n)}function nn(t,e="utf-8"){"."===t[0]&&(t=t.substring(1));const n=Ye.get(t)??"application/octet-stream";return n.startsWith("text/")&&!n.includes("charset=")?`${n}; charset=${e}`:n}async function rn(t,e,n){const i=await _(t),r={file:t,mime:nn(m(t)),rawSize:i.byteLength,bestSize:i.byteLength,created:0};if(r.rawSize<=n)return r;if(["image","video","audio","font"].includes(r.mime.split("/")[0]))return r;for(const o of e){const e=cn.get(o.match),s=y(g(t),Ze(b(t),o.file));if(!e||s===o.file)continue;const c=await e(i);c.byteLength<=r.rawSize-n&&(await T(s,c),r.bestSize=Math.min(r.bestSize,c.byteLength),++r.created)}return r}async function on(t,e,n){const i=[];await sn(t,i);const r=new Set(i);for(const t of r)for(const n of e){const e=y(g(t),Ze(b(t),n.file));e!==t&&r.delete(e)}return Promise.all([...r].map(t=>rn(t,e,n)))}async function sn(t,e){const n=await x(t);if(n.isDirectory())for(const n of await S(t))await sn(y(t,n),e);else n.isFile()&&e.push(t)}const cn=/*@__PURE__*/new Map([["zstd",t=>p(w.zstdCompress)(t)],["br",t=>p(w.brotliCompress)(t,{params:{[w.constants.BROTLI_PARAM_QUALITY]:w.constants.BROTLI_MAX_QUALITY,[w.constants.BROTLI_PARAM_SIZE_HINT]:t.length}})],["gzip",t=>p(w.gzip)(t,{level:w.constants.Z_BEST_COMPRESSION})],["deflate",t=>p(w.deflate)(t)]]),an=(t,e)=>{const n=at(t);n.U(e,n.I?"handling upgrade":"handling request",t)},fn=(t,{onlyIfRequested:e=!0,emitError:n=!0,forceStatus:i,contentType:r="application/json"}={})=>({handleError:(o,s,c)=>{if(c.hasUpgraded||e&&!un(s,r))throw o;n&&an(s,o);const a=ce(c);if(!a)return;const f=V(o,oe)??new oe(500),u=JSON.stringify(t(f));a.setHeaders(f.headers),a.setHeader("content-type",r),a.setHeader("content-length",String(Buffer.byteLength(u,"utf-8"))),c.response||a.setHeader("connection","close"),i?a.writeHead(i):a.writeHead(f.statusCode,f.statusMessage),a.end(u,"utf-8")},shouldHandleError:(t,n,i)=>!i.hasUpgraded&&(!e||un(n,r))}),un=(t,e)=>Se(t.headers.accept)?.some(t=>t.name===e||"application/json"===t.name)??!1;class hn{constructor(t,{subDirectories:e=!0,caseSensitive:n="exact",allowAllDotfiles:i=!1,allowAllTildefiles:r=!1,allowDirectIndexAccess:o=!1,allow:s=[".well-known"],hide:c=[],indexFiles:a=["index.htm","index.html"],implicitSuffixes:f=[],negotiation:u}){this.Ht=t,this.qt=!0===e?Number.POSITIVE_INFINITY:e||0,this.Lt=n,this.zt=i,this.Wt=r,this.Gt=o,this.Jt=a,this.Vt=["",...f],this.Zt=new Set(s.map(t=>this.Xt(t))),this.Yt=new Set,this.Kt=[];for(const t of c)"string"==typeof t?this.Yt.add(this.Xt(t)):this.Kt.push(Le(t,!n));this.Qt=new Set(a.map(t=>this.Xt(t))),u?.length?(this.te=Je(u),this.vary=this.te.vary):this.vary=""}static async build(t,e){return new hn(await k(t,{encoding:"utf-8"})+v,e)}Xt(t){return"exact"===this.Lt?t:t.toLowerCase()}ee(t){if(this.Zt.has(t))return!0;const e=t.trim();return!(!("~"!==e[0]&&"~"!==e[e.length-1]||this.Wt)||"."===e[0]&&!this.zt||this.Yt.has(e)||this.Kt.some(t=>t.test(e)))}async find(t,e={}){let n=t.join(v);"force-lowercase"===this.Lt&&(n=n.toLowerCase());let i=E(this.Ht,n);if(!i.startsWith(this.Ht)&&i+v!==this.Ht)return null;let r=null,o=null;for(const t of this.Vt){const e=i+t;if(r=e.substring(this.Ht.length).split(v).filter(t=>t),r.length>this.qt+1)return null;if(r.some(t=>!this.ee(this.Xt(t))))return null;const n=r[r.length-1]??"";if(!this.Gt&&this.Qt.has(this.Xt(n))&&!this.Zt.has(this.Xt(n)))return null;if(o=await k(e,{encoding:"utf-8"}).catch(()=>null),o){i=e;break}}if(!o||!r)return null;if(this.Xt(o)!==this.Xt(i))return null;let s=o,c=await x(o).catch(()=>null);if(!c)return null;if(c.isDirectory()){if(r.length>this.qt)return null;for(const t of this.Jt){const e=y(o,t);if(c=await x(e).catch(()=>null),c?.isFile()){s=e;break}}}if(!c?.isFile())return null;if(this.te){const t=b(s),n=g(s);for(const i of this.te.options(t,e)){if(!i.filename||i.filename.includes(v))continue;const t=await dn({canonicalPath:s,negotiatedPath:y(n,i.filename),...i.info});if(t)return t}}return dn({canonicalPath:s,negotiatedPath:s})}async precompute(){const t=new Map,e=(e,n)=>{const i=t.get(e);(!i||n.p>i.p)&&t.set(e,n)},n=new G({dir:[this.Ht],depth:0});for(const{dir:t,depth:i}of n){const r=await S(y(...t),{withFileTypes:!0,encoding:"utf-8"}),o=new Set(r.map(t=>this.Xt(t.name)));for(const s of r){const r=this.Xt(s.name);if(!this.ee(r))continue;const c=[...t,s.name];if(s.isDirectory())i<this.qt&&n.push({dir:c,depth:i+1}),e(this.Xt(c.slice(1).join("/")),ln);else if(s.isFile()){const n={file:y(...c),dir:y(...t),basename:r,siblings:o},i=this.Jt.indexOf(r);if(-1!==i&&(e(this.Xt(t.slice(1).join("/")),{...n,p:this.Jt.length+1-i}),!this.Gt&&!this.Zt.has(r)))continue;const a=this.Xt(c.slice(1).join("/"));for(let t=0;t<this.Vt.length;++t){const i=this.Vt[t];s.name.endsWith(i)&&e(a.substring(0,a.length-i.length),{...n,p:-t})}}}}return{find:async(e,n={})=>{const i=t.get(this.Xt(e.join("/")));if(!i?.file)return null;if(this.te)for(const t of this.te.options(i.basename,n)){if(!i.siblings.has(this.Xt(t.filename)))continue;const e=await dn({canonicalPath:i.file,negotiatedPath:y(i.dir,t.filename),...t.info});if(e)return e}return dn({canonicalPath:i.file,negotiatedPath:i.file})},vary:this.vary}}}const ln={file:"",dir:"",basename:"",siblings:new Set,p:1};async function dn(t){const e=await $(t.negotiatedPath,a.O_RDONLY).catch(()=>null);if(!e)return null;const n=()=>(e.close().catch(()=>{}),null),i=await e.stat().catch(n);return i?.isFile()?{handle:e,stats:i,...t}:n()}const wn=/*@__PURE__*/Oe(async t=>{const e=Tt(t);if(e.aborted)throw St;e.throwIfAborted();const n=await A(y(O(),"upload"));_t(t,()=>N(n,{recursive:!0}));let i=0;const r=()=>{if(e.aborted)throw St;return y(n,(++i).toString(10).padStart(6,"0"))};return{dir:n,nextFile:r,save:async(t,{mode:n=384}={})=>{const i=r(),o=f(i,{mode:n});try{return await d(t,o,{signal:e}),{path:i,size:o.bytesWritten}}finally{o.close()}}}});function pn(t){const e=at(t);if(!e.B)throw new TypeError("cannot call acceptBody from shouldUpgrade");if(e.C.signal.aborted)throw St;e.ne||e.I||(e.ne=!0,"100-continue"===t.headers.expect?.trim().toLowerCase()&&e.B.j.writeContinue())}function mn(t,{blockRequestHeaders:e=["connection","expect","host","keep-alive","proxy-authorization","transfer-encoding","upgrade","via"],requestHeaders:n=[],blockResponseHeaders:i=["connection","keep-alive","transfer-encoding"],responseHeaders:s=[],agent:c,keepAlive:a=!0,maxSockets:f=10,...u}={}){let h;t.startsWith("https://")?(c??=new P({keepAlive:a,maxSockets:f,...u}),h=o):(c??=new r({keepAlive:a,maxSockets:f,...u}),h=F);const l=t.endsWith("/")?t:t+"/";return qt((r,o)=>new Promise((a,f)=>{const u=Tt(r),w=t=>f(u.aborted?St:new oe(502,{cause:t})),p=new URL(l+r.url?.substring(1)),m=p.toString();if(!m.startsWith(l)&&m!==t)return f(new oe(400,{message:"directory traversal blocked"}));pn(r);let y={...r.headers};yn(y,e);for(const t of n)y=t(r,y);const g=h(p,{agent:c,method:r.method,headers:y,signal:u});g.once("error",w),g.once("response",t=>{if(!o.headersSent){let e={...t.headers};yn(e,i);for(const n of s)e=n(r,t,e);o.writeHead(t.statusCode??200,t.statusMessage,e)}d(t,o).then(a,f)}),d(r,g).catch(w)}))}function yn(t,e){for(const e of Te(t.connection)??[])delete t[e.toLowerCase()];for(const n of e)delete t[n]}function gn({trustedProxyCount:t,trustedProxyAddresses:e,trustedHeaders:n}){const i=e?q(e):()=>!0,r=t??(e?Number.POSITIVE_INFINITY:0),o=new Set(n);return Oe(t=>{const e=e=>{if(o.has(e))return Te(t.headers[e])?.reverse()},n=e("forwarded"),s=e("x-forwarded-for"),c=e("x-forwarded-host"),a=e("x-forwarded-proto"),f=e("x-forwarded-protocol"),u=e("x-url-scheme"),h=e("via")?.map(t=>{const e=/^([^/ ]+\/)?([^ ]+) (.+)$/.exec(t);return e?.[3]?H(e[3]):void 0}),l=[bn(t)];if(n)for(const t of n)try{const e=ke(t);l.push({client:H(e.get("for")),server:H(e.get("by")),host:e.get("host"),proto:e.get("proto")})}catch{l.push({client:void 0,server:void 0,host:void 0,proto:void 0})}else if(s){const t=s.map(H),e=c??[],n=a??f??u??[];let i=l[0].client;for(let r=0;r<t.length;++r){const o=t[r];l.push({client:o,server:h?.[r]??(i?{...i,port:void 0}:void 0),host:e[r],proto:n[r]}),i=o}}else if(h)for(const t of h)l.push({client:void 0,server:t,host:void 0,proto:void 0});let d=Math.min(1+r,l.length);for(let t=0;t<d-1;++t)i(l[t].client)||(d=t+1);return Object.freeze({trusted:l.slice(0,d),untrusted:l.slice(d),outwardChain:l,edge:l[d-1]})})}const bn=t=>({client:{...H(t.socket.remoteAddress)??vn,port:t.socket.remotePort},server:{...H(t.socket.localAddress)??vn,port:t.socket.localPort},host:t.headers.host,proto:void 0}),vn={type:"alias",ip:"_disconnected",port:void 0};function En(t,e){return delete e.forwarded,delete e["x-forwarded-for"],delete e["x-forwarded-host"],delete e["x-forwarded-proto"],delete e["x-forwarded-protocol"],delete e["x-url-scheme"],e}function _n(t,e){const n=En(0,e);return n.forwarded=Sn([bn(t)]),n}const Tn=(t,{onlyTrusted:e=!1}={})=>(n,i)=>{const r=En(0,i),o=t(n);return r.forwarded=Sn([...e?o.trusted:o.outwardChain].reverse()),r};function xn(t,e){let n=t.headers.forwarded;const i=Sn([bn(t)]);n?n+=", "+i:n=i;const r=En(0,e);return r.forwarded=n,r}function Sn(t){return t.filter(t=>t.server||t.client).map(t=>Object.entries({for:t.client?.ip,by:t.server?.ip,host:t.host,proto:t.proto}).filter(([t,e])=>e).map(([t,e])=>e&&/[^a-zA-Z0-9._]/.test(e)?`${t}="${e.replaceAll("\\","\\\\").replaceAll('"','\\"').replaceAll(",","-")}"`:`${t}=${e}`).join("; ")).join(", ")}class kn{constructor(t,{fatal:e=!1}={}){this.ie=t,this.re=e,this.oe=new Uint8Array(4),this.se=new DataView(this.oe.buffer),this.ce=0}decode(t,{stream:e=!1}={}){const n=t.byteLength,i=[];let r=0;if(this.ce>0){if(r=4-this.ce,n<r)return this.oe.set(t,this.ce),this.ce+=n,"";this.oe.set(t.subarray(0,r),this.ce),i.push(this.se.getUint32(0,this.ie)),this.ce=0}const o=new DataView(t.buffer,t.byteOffset,t.byteLength);let s=r;for(const t=n-3;s<t;s+=4)i.push(o.getUint32(s,this.ie));if(e?(s<n&&this.oe.set(t.subarray(s)),this.ce=n-s):(this.ce=0,s<n&&(this.re?ft(new TypeError("The encoded data was not valid for encoding utf-32"),"ERR_ENCODING_INVALID_ENCODED_DATA"):i.push(65533))),i.length>0){try{return String.fromCodePoint(...i)}catch{this.re&&ft(new TypeError("The encoded data was not valid for encoding utf-32"),"ERR_ENCODING_INVALID_ENCODED_DATA")}for(let t=0;t<i.length;++t)i[t]>1114111&&(i[t]=65533);return String.fromCodePoint(...i)}return""}}class $n extends C{constructor(t){super({transform(e,n){try{const i=t.decode(e,{stream:!0});i&&n.enqueue(i)}catch(t){n.error(t)}},flush(e){try{const n=t.decode(X);n&&e.enqueue(n)}catch(t){e.error(t)}}})}}const An=new Map;function Nn(t,e){An.set(t.toLowerCase(),e)}function On(){Nn("utf-32be",{decoder:t=>new kn(!1,t)}),Nn("utf-32le",{decoder:t=>new kn(!0,t)})}function Rn(t,e={}){const n=An.get(t.toLowerCase());if(n)return n.decoder(e);try{return new TextDecoder(t,e)}catch{throw new oe(415,{body:`unsupported charset: ${t}`})}}function Pn(t,e={}){const n=An.get(t.toLowerCase());if(n)return n.decoderStream?n.decoderStream(e):new $n(n.decoder(e));try{return new U(t,e)}catch{throw new oe(415,{body:`unsupported charset: ${t}`})}}const Fn=["utf-32be",null,"utf-16be","utf-16be","utf-32le","utf-16le",null,"utf-8"];function Cn(t,e,n){const i=$e(t.headers["if-modified-since"]),r=Te(t.headers["if-none-match"]);if(r){if(Mn(e,n,r))return!1}else if(i&&(n.mtimeMs/1e3|0)<=i)return!1;return!0}function Un(t,e,n){let i=!0;const r=Ee(t);return r.etag&&(i&&=Mn(e,n,r.etag)),r.modifiedSeconds&&(i&&=(n.mtimeMs/1e3|0)===r.modifiedSeconds),i}function Mn(t,e,n){if(n.includes("*"))return!0;const i=t.getHeader("etag");if("string"==typeof i){if(n.includes(i))return!0;if(i.startsWith('W/"'))return!1}return!!n.some(t=>t.startsWith('W/"'))&&n.includes(He(t.getHeader("content-encoding"),e))}class Dn extends C{constructor(t,e){super({transform(i,r){n+=i.byteLength,n>t?r.error(e):r.enqueue(i)}});let n=0}}function In(t,{maxContentBytes:e=Number.POSITIVE_INFINITY,maxNetworkBytes:n=e,maxEncodingSteps:i=1}={}){const r=xe(t.headers["content-length"]);if(void 0!==r&&r>n)throw new oe(413);const o=Te(t.headers["content-encoding"])??[];if(o.length>i)throw new oe(415,{body:"too many content-encoding stages"});pn(t);let s=I.toWeb(t);void 0===r&&Number.isFinite(n)&&(s=s.pipeThrough(new Dn(n,new oe(413))));for(const t of o.reverse())s=s.pipeThrough(qn(t));return Number.isFinite(e)&&(s=s.pipeThrough(new Dn(e,new oe(413,{body:"decoded content too large"})))),s}function Bn(t,e={}){const n=In(t,e),i=ve(t)??e.defaultCharset??"utf-8";return n.pipeThrough(Pn(i,e))}async function jn(t,e={}){const n=[];for await(const i of Bn(t,e))n.push(i);return n.join("")}async function Hn(t,e={}){const n=await(async(t,e)=>{const n=t.getReader(),i=new Uint8Array(3);let r=0,o=null;for(;;){const t=await n.read(),e=3-r;if(t.done){0===r?(i[0]=1,i[1]=1):1===r&&(i[1]=i[0]),i[2]=i[0],o=null;break}if(o=t.value,o.byteLength>=e){i.set(o.subarray(0,e),r);break}i.set(o,r),r+=o.byteLength}const s=Fn[(i[0]?4:0)|(i[1]?2:0)|(i[2]?1:0)];if(!s)throw n.cancel(),new oe(415,{body:"invalid JSON encoding"});const c=Pn(s,e),a=c.writable.getWriter();return r&&a.write(i.subarray(0,r)),o&&a.write(o),n.releaseLock(),a.releaseLock(),t.pipeThrough(c)})(In(t,e),e),i=[];for await(const t of n)i.push(t);return JSON.parse(i.join(""))}function qn(t){switch(t.toLowerCase()){case"gzip":case"x-gzip":return new M("gzip");case"deflate":return new M("deflate");case"br":try{return new M("brotli")}catch{return B.toWeb(w.createBrotliDecompress())}case"zstd":try{return B.toWeb(w.createZstdDecompress())}catch{throw new oe(415,{body:"unsupported content encoding"})}default:throw new oe(415,{body:"unknown content encoding"})}}function Ln(t){if(!t)return null;const[e,n]=ge(t,";"),i=new Map;if(n){const t=/\s*([!#-'*+\-.0-:>-Z^-z|~]+)=(?:([!#-'*+\-.0-:>-Z^-z|~]+)|"((?:[^\x00-\x08\x0a-\x1f"\\\x7f]|\\.)*)")\s*(;|$)/gy;for(;t.lastIndex!==n.length;){const e=t.exec(n);if(!e)return null;const r=e[1].toLowerCase(),o=e[2]??e[3]?.replaceAll(/\\(.)/g,"$1")??"";i.has(r)||i.set(r,o)}}return{mime:e.trim().toLowerCase(),params:i}}function zn(t,e,n,i){const r=t.byteLength;for(;e<r;){for(;e<r;++e){const n=t[e];if(32!==n&&9!==n)break}if(e===r)break;if(59!==t[e++])return!1;for(;e<r;++e){const n=t[e];if(32!==n&&9!==n)break}if(e===r)return!1;const o=e;for(;e<r;++e){const n=t[e];if(!Gn[n]){if(61===n)break;return!1}}if(e===r)return!1;const s=t.latin1Slice(o,e).toLowerCase();if("*"===s[s.length-1]){const i=++e;for(;e<r;++e){const n=t[e];if(!Vn[n]){if(39!==n)return!1;break}}if(e===r)return!1;const o=Rn(t.latin1Slice(i,e));for(++e;e<r&&39!==t[e];++e);if(e===r)return!1;if(++e===r)return!1;let c=e;const a=[];for(;e<r;++e){const n=t[e];if(1!==Jn[n]){if(37===n){let n,i;if(e+2<r&&16!==(n=Xn[t[e+1]])&&16!==(i=Xn[t[e+2]])){const r=(n<<4)+i;e>c&&a.push(o.decode(t.subarray(c,e),{stream:!0})),a.push(o.decode(Buffer.from([r]),{stream:!0})),c=(e+=2)+1;continue}return!1}break}}a.push(o.decode(t.subarray(c,e)));const f=a.join("");n.has(s)||n.set(s,f);continue}if(++e===r)return!1;if(34===t[e]){let o=++e,c=!1;const a=[];for(;e<r;++e){const n=t[e];if(92!==n){if(34===n){if(c){o=e,c=!1;continue}a.push(i.decode(t.subarray(o,e)));break}if(c&&(o=e-1,c=!1),!Zn[n])return!1}else c?(o=e,c=!1):(a.push(i.decode(t.subarray(o,e),{stream:!0})),c=!0)}if(e===r)return!1;++e,n.has(s)||n.set(s,a.join(""));continue}let c=e;for(;e<r;++e){const n=t[e];if(!Gn[n]){if(e===c)return!1;break}}n.has(s)||n.set(s,i.decode(t.subarray(c,e)))}return!0}const Wn=[1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],Gn=/*@__PURE__*/(()=>{const t=new Uint8Array(256);return t.set([1,0,1,1,1,1,1,0,0,1,1,0,1,1,0,...Wn,0,1,0,1],33),t})(),Jn=/*@__PURE__*/(()=>{const t=new Uint8Array(256);return t.set([1,0,1,1,0,1,0,0,0,0,1,0,1,1,0,...Wn,0,1,0,1],33),t})(),Vn=/*@__PURE__*/(()=>{const t=new Uint8Array(256);return t.set([1,0,1,1,1,1,0,0,0,0,1,0,1,0,0,...Wn,1,0,1,1],33),t})(),Zn=/*@__PURE__*/(()=>{const t=new Uint8Array(256);return t.fill(1,32,256),t[9]=1,t[34]=0,t[92]=0,t[127]=0,t})(),Xn=/*@__PURE__*/(()=>{const t=new Uint8Array(256).fill(16);for(let e=0;e<10;++e)t[48+e]=e;for(let e=0;e<6;++e)t[65+e]=e+10,t[97+e]=e+10;return t})();class Yn{constructor(t,e){const n=t.byteLength;if(!n||n>65535)throw new RangeError("invalid needle");this.ae=t,this.fe=e,this.ue=null,this.he=0,this.le=null}push(t){let e=0;const n=t.byteLength,i=this.ae,r=i.byteLength-1,o=n-r;let s=-this.he;if(this.he){const c=this.le,a=this.ue,f=i[r];if(o>0){const n=t[s+r];n!==f||t.compare(i,-s,r,0,s+r)?s+=c[n]:(this.fe(!0,X,0,0,!0),this.he=0,e=s+=r+1)}const u=o<0?o:0;for(;s<u;){const n=t[s+r];if(n===f&&!a.compare(i,0,-s,this.he+s,this.he)&&!t.compare(i,-s,r,0,s+r)){this.fe(!0,a,0,this.he+s,!1),this.he=0,e=s+=r+1;break}s+=c[n]}const h=this.he;if(h>0){const e=i[0];for(;s<0;){const r=a.subarray(0,h).indexOf(e,h+s);if(-1===r){s=0;break}const o=h-r;if(!a.compare(i,1,o,r+1,h)&&!t.compare(i,o,o+n))return r&&(this.fe(!1,a,0,r,!1),a.copy(a,0,r,o)),a.set(t,o),void(this.he+=n-r);s=r+1-h}this.fe(!1,a,0,h,!1),this.he=0}}for(;s<o;){const n=t.indexOf(i,s);if(-1!==n){if(this.fe(!0,t,e,n,!0),n===o+1)return;e=s=n+r+1}else s=o}const c=i[0];for(;s<n;){const o=t.indexOf(c,s);if(-1===o)return void this.fe(!1,t,e,n,!0);if(!t.compare(i,1,n-o,o+1)){if(!this.ue){this.ue=Buffer.allocUnsafe(r),this.le=new Uint16Array(256).fill(r+1);for(let t=0;t<r;++t)this.le[i[t]]=r-t}return t.copy(this.ue,0,o),this.he=n-o,void(o>e&&this.fe(!1,t,e,o,!0))}s=o+1}n>e&&this.fe(!1,t,e,n,!0)}destroy(){const t=this.he;t&&this.ue&&this.fe(!1,this.ue,0,t,!1),this.he=0}}class Kn extends j{constructor({limits:t={},preservePath:e,highWaterMark:n,fileHwm:i,defParamCharset:r="utf-8",defCharset:o="utf-8"},s){super({autoDestroy:!0,emitClose:!0,highWaterMark:n,write:Qn,destroy:ti,final:ei});const c=s.get("boundary");if(!c)throw new oe(400,{body:"multipart boundary not found"});if(c.length>70)throw new oe(400,{body:"multipart boundary too long"});const a=Rn(r),f={autoDestroy:!0,emitClose:!0,highWaterMark:i},u=t.fieldSize??1048576,h=t.fileSize??Number.POSITIVE_INFINITY,l=t.fieldNameSize??100,d=t.files??Number.POSITIVE_INFINITY,w=t.fields??Number.POSITIVE_INFINITY,p=t.parts??Number.POSITIVE_INFINITY;let m,y,g,b,v,E=0,_=0,T=0,x=-1;this.de=0,this.we=!1;let S=!1;const k=new ni(t=>{this.pe=void 0;const n=t["content-disposition"];if(!n)return void(x=-1);const i=((t,e)=>{if(!t.byteLength)return null;const n=new Map;let i=0;for(;i<t.byteLength;++i)if(!Gn[t[i]]){if(!zn(t,i,n,e))return null;break}return{type:t.latin1Slice(0,i).toLowerCase(),params:n}})(Buffer.from(n,"latin1"),a);if("form-data"!==i?.type)return void(x=-1);v=i.params.get("name")??"",S=v.length>l,S&&(v=v.substring(0,l));let r=i.params.get("filename*")??i.params.get("filename");void 0===r||e||(r=(t=>{for(let e=t.length;e-- >0;)if("/"===t[e]||"\\"===t[e]){t=t.slice(e+1);break}return".."===t||"."===t?"":t})(r));const s=Ln(t["content-type"]);b=s?.mime??"text/plain";const c=s?.params.get("charset")?.toLowerCase()??o;if(y=Rn(c),g=t["content-transfer-encoding"]?.toLowerCase()??"7bit","application/octet-stream"===b||void 0!==r){if(T++===d&&this.emit("filesLimit"),T>d||0===this.listenerCount("file"))return void(x=-1);this.me=new ii(f,this),++this.de,this.emit("file",v,this.me,{nameTruncated:S,filename:r,encoding:g,mimeType:b}),x=h}else{if(_++===w&&this.emit("fieldsLimit"),_>w||0===this.listenerCount("field"))return void(x=-1);m="",x=u}});let $=0;const A=Buffer.from(`\r\n--${c}`,"latin1");this.ye=new Yn(A,(t,e,n,i,r)=>{try{if(n===i)return;if($){if(1===$){if(13===e[n])$=2;else{if(45!==e[n])return void($=0);$=3}if(++n===i)return}if(2!==$){if($=0,45!==e[n])return;return this.we=!0,void(this.ye=oi)}if($=0,10!==e[n++])return;if(E++===p&&this.emit("partsLimit"),E>p)return;if(this.pe=k,n===i)return}if(this.pe){const t=this.pe.push(e,n,i);if(-1===t)return this.pe=void 0,k.reset(),void this.emit("error",new oe(400,{body:"malformed part header"}));if(t===i)return;n=t}if(x>=0){const t=Math.min(i,n+x);if(x-=i-n,this.me){if(t>n){let i;r?i=e.subarray(n,t):(i=Buffer.allocUnsafe(t-n),e.copy(i,0,n,t)),this.me.push(i)||(this.me.ge??=this.be,this.be=void 0)}x<0&&(this.me.emit("limit"),this.me.truncated=!0)}else void 0!==m&&(m+=e.latin1Slice(n,t))}}finally{t&&(this.pe?(this.emit("error",new oe(400,{body:"unexpected end of headers"})),this.pe=void 0):this.me?(this.me.push(null),this.me=void 0):void 0!==m&&(this.emit("field",v,y.decode(Buffer.from(m,"latin1")),{nameTruncated:S,valueTruncated:x<0,encoding:g,mimeType:b}),m=void 0),$=1,x=-1)}}),this.write(si)}ve(){if(this.pe)return new oe(400,{body:"malformed part header"});const t=this.me;return t&&(this.me=void 0,t.destroy(new oe(400,{body:"unexpected end of file"}))),this.we?null:new oe(400,{body:"unexpected end of form"})}}function Qn(t,e,n){this.be=n,this.ye.push(t);const i=this.be;i&&(this.be=void 0,i())}function ti(t,e){this.pe=void 0,this.ye=oi,t??=this.ve();const n=this.me;n&&(this.me=void 0,n.destroy(t??void 0)),e(t)}function ei(t){if(this.ye.destroy(),!this.we)return t(new oe(400,{body:"unexpected end of form"}));this.de?this.Ee=()=>t(this.ve()):t(this.ve())}class ni{constructor(t){this._e=Object.create(null),this.Te=0,this.xe=0,this.m=0,this.ht="",this.Se="",this.ke=0,this.fe=t}reset(){this._e=Object.create(null),this.Te=0,this.xe=0,this.m=0,this.ht="",this.Se="",this.ke=0}push(t,e,n){let i=e,r=e;const o=Math.min(n,e+16384-this.xe);for(;r<o;)switch(this.m){case 0:for(;r<o&&Gn[t[r]];++r);if(r>i&&(this.ht+=t.latin1Slice(i,r)),r<o){if(58!==t[r])return-1;if(!this.ht)return-1;++r,this.m=1}break;case 1:for(;r<o;++r){const e=t[r];if(32!==e&&9!==e){i=r,this.m=2;break}}break;case 2:switch(this.ke){case 0:for(;r<o;++r){const e=t[r];if(e<32||127===e){if(13!==e)return-1;++this.ke;break}}this.Se+=t.latin1Slice(i,r),++r;break;case 1:if(10!==t[r++])return-1;++this.ke;break;case 2:{const e=t[r];32===e||9===e?(i=r,this.ke=0):(++this.Te<2e3&&(this._e[this.ht.toLowerCase()]??=this.Se),13===e?(++this.ke,++r):(i=r,this.ke=0,this.m=0,this.ht="",this.Se=""));break}case 3:{if(10!==t[r++])return-1;const e=this._e;return this.reset(),this.fe(e),r}}}return o<n?-1:(this.xe+=o-e,o)}}class ii extends I{constructor(t,e){super({...t,read:ri}),this.truncated=!1,this.once("end",()=>{if(ri.call(this),0===--e.de&&e.Ee){const t=e.Ee;e.Ee=void 0,process.nextTick(t)}})}}function ri(t){const e=this.ge;e&&(this.ge=void 0,e())}const oi={push:()=>{},destroy:()=>{}},si=/*@__PURE__*/Buffer.from("\r\n");class ci extends j{constructor({limits:t={},highWaterMark:e,defCharset:n="utf-8"},i){super({autoDestroy:!0,emitClose:!0,highWaterMark:e,write:ai,final:fi}),this.$e=i.get("charset")??n,this.Ae=t.fieldSize??1048576,this.Ne=t.fields??Number.POSITIVE_INFINITY,this.Oe=t.fieldNameSize??100,this.Re=0,this.Pe=!0,this.Fe="",this.Ce=this.Oe,this.Ue=0,this.Me="",this.De=!1,this.Ie=-2,this.Be=/^utf-?8$/i.test(this.$e)?1:/^(latin-?1|iso[\-_]?8859-?1|(us-)?ascii)$/i.test(this.$e)?2:0,this.je=Rn(this.$e)}}function ai(t,e,n){if(!t.byteLength)return n();if(this.Re>=this.Ne)return this.Re||t===pi||(++this.Re,this.emit("fieldsLimit")),n();const i=t.byteLength;let r=0,o=this.Ie;if(-2!==o){if(-1===o){if(16===(o=Xn[t[r++]]))return n(new oe(400,{body:"malformed urlencoded form"}));if(this.Ue|=o,r===i)return this.Ie=o,n()}const e=Xn[t[r++]];if(16===e)return n(new oe(400,{body:"malformed urlencoded form"}));if(this.Fe+=String.fromCharCode((o<<4)+e),this.Ie=-2,r===i)return n()}for(wi[ui]=1,wi[hi]=1,wi[li]=1,wi[di]=this.Pe?1:0;;){const e=r;for(;r<i&&!wi[t[r]];++r);if(r>e&&this.Ce>=0&&((this.Ce-=r-e)<0?this.Fe+=t.latin1Slice(e,r+this.Ce):this.Fe+=t.latin1Slice(e,r)),r===i)return n();switch(t[r++]){case ui:for(;;){if(--this.Ce<0){wi[ui]=0,wi[li]=0;break}if(r===i)return this.Ie=-1,n();const e=Xn[t[r++]];if(16===e)return n(new oe(400,{body:"malformed urlencoded form"}));if(this.Ue|=e,r===i)return this.Ie=e,n();const o=Xn[t[r++]];if(16===o)return n(new oe(400,{body:"malformed urlencoded form"}));if(this.Fe+=String.fromCharCode((e<<4)+o),r===i)return n();if(t[r]!==ui)break;r++}break;case hi:const e=!this.Be||1===this.Be&&8&this.Ue?this.je.decode(Buffer.from(this.Fe,"latin1")):this.Fe;if(this.Pe?(e||this.Ce<0)&&this.emit("field",this.Fe,"",{nameTruncated:this.Ce<0,valueTruncated:!1,encoding:this.$e,mimeType:"text/plain"}):(this.emit("field",this.Me,e,{nameTruncated:this.De,valueTruncated:this.Ce<0,encoding:this.$e,mimeType:"text/plain"}),this.Me="",this.De=!1,this.Pe=!0,wi[di]=1),wi[ui]=1,wi[li]=1,this.Fe="",this.Ce=this.Oe,this.Ue=0,++this.Re===this.Ne&&t!==pi)return this.emit("fieldsLimit"),n();break;case li:--this.Ce<0?(wi[ui]=0,wi[li]=0):this.Fe+=" ";break;case di:this.Me=!this.Be||1===this.Be&&8&this.Ue?this.je.decode(Buffer.from(this.Fe,"latin1")):this.Fe,this.De=this.Ce<0,this.Pe=!1,wi[di]=0,wi[ui]=1,wi[li]=1,this.Fe="",this.Ue=0,this.Ce=this.Ae}if(r===i)return n()}}function fi(t){ai.call(this,pi,void 0,t)}const ui=37,hi=38,li=43,di=61,wi=/*@__PURE__*/new Uint8Array(256),pi=/*@__PURE__*/Buffer.from([hi]);function mi(t,{closeAfterErrorDelay:e=500,...n}={}){const i=((t,e={})=>{const n=t["content-type"];if(!n)throw new oe(400,{body:"missing content-type"});const i=Ln(n);if(!i)throw new oe(400,{body:"malformed content-type"});const r="application/x-www-form-urlencoded"===i.mime?ci:"multipart/form-data"!==i.mime||e.blockMultipart?null:Kn;if(!r)throw new oe(415);return new r(e,i.params)})(t.headers,n);pn(t);const r=new J,o=(n,o)=>{if(r.fail(new oe(n,o)),i.removeAllListeners(),t.unpipe(i),t.resume(),e>=0){const n=setTimeout(()=>t.socket.destroy(),e);t.once("end",()=>clearTimeout(n))}};i.on("field",(t,e,{nameTruncated:n,valueTruncated:i,encoding:s,mimeType:c})=>t?n?o(400,{body:`field name ${JSON.stringify(t)}... too long`}):i?o(400,{body:`value for ${JSON.stringify(t)} too long`}):void r.push({name:t,encoding:s,mimeType:c,type:"string",value:e}):o(400,{body:"missing field name"})),i.on("file",(t,e,{nameTruncated:n,filename:i,encoding:s,mimeType:c})=>t?n?o(400,{body:`field name ${JSON.stringify(t)}... too long`}):void(i?(e.once("limit",()=>o(400,{body:`uploaded file for ${JSON.stringify(t)}: ${JSON.stringify(i)} too large`})),r.push({name:t,encoding:s,mimeType:c,type:"file",value:e,filename:i})):e.resume()):o(400,{body:"missing field name"})),t.once("error",e=>{t.readableAborted?r.fail(St):o(500,{body:"request error",headers:{connection:"close"},cause:e})}),i.once("error",t=>o(400,{body:"error parsing form data",cause:t})),i.once("partsLimit",()=>o(400,{body:"too many parts"})),i.once("filesLimit",()=>o(400,{body:"too many files"})),i.once("fieldsLimit",()=>o(400,{body:"too many fields"}));const s=()=>r.close("complete");return i.once("close",s),_t(t,s),t.pipe(i),r}async function yi(t,e={}){const n=new FormData,i=new Map;for await(const r of mi(t,e))if("file"===r.type){const o=r.value;let s=await(e.preCheckFile?.({fieldName:r.name,filename:r.filename,encoding:r.encoding,mimeType:r.mimeType,maxBytes:e.limits?.fileSize}));const c=t=>{if("function"==typeof s){const e=s;return s=void 0,e({actualBytes:t})}};_t(t,()=>c(0));const a=await wn(t),f=await a.save(o,{mode:384});await c(f.size);const h=new File([await u(f.path)],r.filename,{type:r.mimeType});i.set(h,f.path),n.append(r.name,h)}else{let t=r.value;e.trimAllValues&&(t=t.trim()),n.append(r.name,t)}return Object.assign(n,{getTempFilePath(t){const e=i.get(t);if(!e)throw new RangeError("unknown file");return e},getBoolean(t){const e=n.get(t);return null===e?null:"true"===e||"on"===e},getString(t){const e=n.get(t);return"string"==typeof e?e:null},getAllStrings:t=>n.getAll(t).filter(t=>"string"==typeof t),getFile(t){const e=n.get(t);return"string"==typeof e?null:e},getAllFiles:t=>n.getAll(t).filter(t=>"string"!=typeof t)})}const gi="win32"===/*@__PURE__*/R();function bi(t,{rejectPotentiallyUnsafe:e=!0}={}){let n=[];const i=st(t);if(i){if("/"===i.F)return[];n=i.F.split("/")}else{const e=Y(t).pathname;if("/"===e)return[];n=e.split("/").map(decodeURIComponent)}if(""!==n[0])throw new oe(400,{body:"invalid path"});if(n.shift(),e){const t=gi?Ei:vi;if(n.some(e=>t.test(e)||e.includes(v)))throw new oe(400,{body:"invalid path"});if(n.slice(0,n.length-1).includes(""))throw new oe(400,{body:"invalid path"})}return n}const vi=/[\x00-\x1F\x7F/]|^(\.\.?|~)$/,Ei=/[\x00-\x1F"*/:<>?\\|\x7F]|^[\s.]*$|^(CON|PRN|AUX|NUL|(COM|LPT)[\d\xB9\xB2\xB3])(\.|$)/i,_i=t=>new Promise(e=>{const n=()=>{t.cork(),e()};t instanceof s?t.write(X,n):t.once("drain",n),t.uncork()});async function Ti(t,e,{delimiter:n=",",newline:i="\n",quote:r='"',encoding:o="utf-8",headerRow:c,end:a=!0}={}){"string"==typeof n&&(n=Buffer.from(n,o)),"string"==typeof i&&(i=Buffer.from(i,o));const f="string"==typeof r?Buffer.from(r,o):r,u=r+r,h=e=>{if(!e)return!0;const n=e.includes(r);return!n&&xi.test(e)?t.write(e,o):(t.write(f),n?t.write(e.replaceAll(r,u),o):t.write(e,o),t.write(f))};t instanceof s&&!t.headersSent&&!t.hasHeader("content-type")&&t.setHeader("content-type","text/csv; charset="+o+(c?"; header=present":!1===c?"; header=absent":"")),t.cork();try{t.write(X);for await(const r of e){if(t.writableAborted)break;let e=0;if(Symbol.iterator in r)for(const i of r)e&&t.write(n),h(i)||await _i(t),++e;else for await(const i of r)e&&t.write(n),h(i)||await _i(t),++e;t.write(i)||await _i(t)}}finally{t.uncork()}a&&t.end()}const xi=/^[^"':;,\\\r\n\t ]*$/i;function Si(t){if(!t||"object"!=typeof t)return!1;const e=t;return"number"==typeof e.fd&&"function"==typeof e.stat&&"function"==typeof e.createReadStream}class ki{constructor(t){(t=>"He"in t&&"function"==typeof t.pipe)(t)&&(t=I.toWeb(t)),this.lt=t.getReader(),this.qe=null,this.Le=0,this.m=0}getRange(t,e){if(e<t)throw new RangeError("invalid range");if(t<this.Le)throw new RangeError("non-sequential range");if(this.m)throw new TypeError("previous range still active");let n=e-t+1,i=t-this.Le;this.Le=e+1,this.m=1;const r=this,o=(t,e)=>{const r=t.byteLength;r<=i?i-=r:r>i+n?(this.qe=t.subarray(i+n),e.enqueue(t.subarray(i,i+n)),n=0):i>0?(e.enqueue(t.subarray(i)),n-=r-i,i=0):(e.enqueue(t),n-=r)};return new D({start(t){if(r.qe){const e=r.qe;r.qe=null,o(e,t)}},async pull(t){if(n<=0)return r.m=0,void t.close();const e=await r.lt.read();e.done?t.error(new RangeError("range exceeds content")):"string"==typeof e.value?o(Buffer.from(e.value,"utf-8"),t):e.value instanceof Uint8Array?o(e.value,t):t.error(new TypeError("invalid stream type: must contain bytes or UTF-8 text"))}})}async close(){await this.lt.cancel(),this.lt.releaseLock()}}function $i(t,{forceSequential:e=!1,mergeOverlapDistance:n=100}={}){const i=[];if(n>=0)for(const e of t.ranges){let t=null,r=0;for(let o=0;o<i.length;++o){const s=i[o];e.end>=s.start-n-1&&s.end>=e.start-n-1?t?(++r,t.start=Math.min(t.start,s.start),t.end=Math.max(t.end,s.end)):(t=s,t.start=Math.min(t.start,e.start),t.end=Math.max(t.end,e.end)):r>0&&(i[o-r]=s)}t?i.length-=r:i.push({...e})}else i.push(...t.ranges);if(e)for(let t=0;t<i.length-1;++t)if(i[t].start>i[t+1].start){i.sort((t,e)=>t.start-e.start);break}return{ranges:i,totalSize:t.totalSize}}async function Ai(t,e,n,i){if("string"==typeof n||Si(n)||(i=$i(i,{mergeOverlapDistance:0,forceSequential:!0})),1===i.ranges.length){const r=i.ranges[0];if(e.setHeader("content-length",r.end-r.start+1),e.setHeader("content-range",`bytes ${r.start}-${r.end}/${i.totalSize??"*"}`),e.writeHead(206),"HEAD"===t.method)return void e.end();const o=await Ni(n);return await d(o.ze(r.start,r.end),e),void(o.We&&await o.We())}const r=e.getHeader("content-type"),o=l()+l()+"ABCDEFGHIJKLMNOPQRSTUVWXYZ";e.setHeader("content-type",`multipart/byteranges; boundary=${o}`);const s=i.ranges.map(t=>({o:[`--${o}`,...ht({"content-type":r,"content-range":`bytes ${t.start}-${t.end}/${i.totalSize??"*"}`}),"",""].join("\r\n"),Ge:t})),c=`--${o}--`;let a=c.length;for(const{o:t,Ge:e}of s)a+=t.length+e.end-e.start+1+2;if(e.setHeader("content-length",a),"HEAD"===t.method)return void e.end();let f="";const u=await Ni(n);try{for(const{o:t,Ge:n}of s)e.write(f+t,"ascii"),await d(u.ze(n.start,n.end),e,{end:!1}),f="\r\n";e.end(f+c)}finally{u.We&&await u.We()}}async function Ni(t){if("string"==typeof t){const e=await $(t,"r");return{ze:(t,n)=>e.createReadStream({start:t,end:n,autoClose:!1}),We:()=>e.close()}}if(Si(t))return{ze:(e,n)=>t.createReadStream({start:e,end:n,autoClose:!1})};{const e=new ki(t);return{ze:(t,n)=>e.getRange(t,n),We:()=>e.close()}}}async function Oi(t,e,n,i,r){if(i||("string"==typeof n?i=await x(n):Si(n)&&(i=await n.stat())),i){if("GET"===t.method||"HEAD"===t.method){if(!Cn(t,e,i))return void e.writeHead(304).end();e.setHeader("accept-ranges","bytes");const o=_e(t,i.size,r);if(o&&Un(t,e,i))return Ai(t,e,n,$i(o,r))}e.setHeader("content-length",i.size)}if(e.writeHead(e.statusCode,e.statusMessage),"HEAD"!==t.method)return"string"==typeof n?n=c(n):Si(n)&&(n=n.createReadStream({start:0,autoClose:!1})),d(n,e);e.end()}function Ri(t,e,{replacer:n,space:i,undefinedAsNull:r=!1,encoding:o="utf-8",end:c=!0}={}){const a=JSON.stringify(e,n,i)??(r?"null":void 0);t instanceof s&&!t.headersSent&&(t.hasHeader("content-type")||t.setHeader("content-type","application/json"),c&&t.setHeader("content-length",Buffer.byteLength(a,o))),c?t.end(a,o):a&&t.write(a,o)}async function Pi(t,e,{replacer:n=null,space:i="",undefinedAsNull:r=!1,encoding:o="utf-8",end:c=!0}={}){if(Array.isArray(n)){const t=new Set(n.map(t=>String(t)));n=function(e,n){return null===this||Array.isArray(this)||t.has(e)?n:void 0}}"number"==typeof i&&(i=" ".substring(0,i));const a={Je:e=>t.write(e,o),Ve:()=>_i(t),Ze:n,Xe:i};if(t instanceof s&&!t.headersSent&&!t.hasHeader("content-type")&&t.setHeader("content-type","application/json"),e=Ci(null,"",e,a),Ui(e))r&&a.Je("null");else{t.cork(),t.write(X);try{await Fi(a,e,i?"\n":"")}finally{t.uncork()}}c&&t.end()}async function Fi(t,e,n){const i=(i,r,o)=>{t.Je(i);const s=n+t.Xe,c=t.Xe?": ":":";let a=!0;return{i:async(n,i)=>{const r=Ci(e,n,i,t);o&&Ui(r)||(a?a=!1:t.Je(","),t.Je(s),o&&(t.Je(JSON.stringify(n))||await t.Ve(),t.Je(c)),await Fi(t,r,s))},We:()=>{a||t.Je(n),t.Je(r)}}};if(null===e||"object"!=typeof e||e instanceof String||e instanceof Number||e instanceof Boolean||e instanceof Function||e instanceof Symbol||e instanceof BigInt||Mi(e))t.Je(JSON.stringify(e)??"null")||await t.Ve();else if(e instanceof I){t.Je('"');for await(const n of e){if("string"!=typeof n)throw new TypeError("Readables must have an encoding");const e=JSON.stringify(n);t.Je(e.substring(1,e.length-1))||await t.Ve()}t.Je('"')}else if(e instanceof Map){const t=i("{","}",!0);for(const[n,i]of e)await t.i(n,i);t.We()}else if(Di(e)){let t=0;const n=i("[","]",!1);for(const i of e)await n.i(String(t++),i);n.We()}else if(Ii(e)){let t=0;const n=i("[","]",!1);for await(const i of e)await n.i(String(t++),i);n.We()}else{const t=i("{","}",!0);for(const[n,i]of Object.entries(e))await t.i(n,i);t.We()}}function Ci(t,e,n,i){return i.Ze&&(n=i.Ze.call(t,e,n)),n&&"object"==typeof n&&"function"==typeof n.toJSON&&(n=n.toJSON(e)),n}const Ui=t=>void 0===t||"function"==typeof t||"symbol"==typeof t||t instanceof Function||t instanceof Symbol,Mi=t=>JSON.isRawJSON?.(t)??!1,Di=t=>Symbol.iterator in t,Ii=t=>Symbol.asyncIterator in t;class Bi{constructor(t,e,{keepaliveInterval:n=15e3,softCloseReconnectDelay:i=500,softCloseReconnectStagger:r=2e3}={}){this.Ye=e,this.Ke=n??0,this.C=new AbortController,e.setHeader("content-type","text/event-stream"),e.setHeader("x-accel-buffering","no"),e.setHeader("cache-control","no-store"),e.writeHead(200),e.flushHeaders(),this.ping=this.ping.bind(this),this.Qe(),t.once("close",()=>this.close()),wt(t,()=>this.close(i,r))}get signal(){return this.C.signal}get open(){return!this.C.signal.aborted}Qe(){this.Ke&&(this.tn=setTimeout(this.ping,this.Ke))}ping(){!this.C.signal.aborted&&this.Ye.writable&&(clearTimeout(this.tn),this.Ye.write(":\n\n",()=>this.Qe()))}send({event:t,id:e,data:n,reconnectDelay:i=-1}){return this.sendFields([["event",t],["id",e],["data",n],["retry",i>=0?String(0|i):void 0]])}async sendFields(t){let e;this.C.signal.throwIfAborted(),this.Ye.cork();try{let n=!1;for(const[e,i]of t){if(void 0===i)continue;const t=i.split(/(?<=\n)|(?<=\r)(?!\n)/g);for(let n of t)this.Ye.write(e)," "===n[0]?this.Ye.write(": "):this.Ye.write(":"),this.Ye.write(n);/[\r\n]$/.test(i)?(this.Ye.write(e),this.Ye.write(":\n")):this.Ye.write("\n"),n=!0}if(!n)return;clearTimeout(this.tn),this.Ye.write("\n",()=>e())}finally{this.Ye.uncork()}await new Promise(t=>{e=t}),this.Qe()}async close(t=0,e=0){if(this.C.signal.aborted){if(this.Ye.closed)return;return new Promise(t=>this.Ye.once("close",t))}this.Ke=0,clearTimeout(this.tn),this.C.abort(new Error("ServerSentEvents closed")),await new Promise(n=>{if(this.Ye.writable&&(t>0||e>0)){const i=t+Math.random()*e;this.Ye.end(`retry:${0|i}\n\n`,n)}else this.Ye.end(n)})}}const ji=async(t,{mode:e="dynamic",fallback:n,callback:i=Hi,...r}={})=>{const o=await hn.build(E(process.cwd(),t),r);let s=null;const c=n?.statusCode??200;if(n){let t=n.filePath;t.startsWith("/")&&(t=t.substring(1)),s=t.split("/")}const a="dynamic"===e?{}:{rejectPotentiallyUnsafe:!1},f="dynamic"===e?o:await o.precompute();return{handleRequest:async(t,e)=>{if("GET"!==t.method&&"HEAD"!==t.method)return kt;let n=!1;const r=bi(t,a),o={mime:Se(t.headers.accept),language:Se(t.headers["accept-language"]),encoding:Se(t.headers["accept-encoding"])};let u=await f.find(r,o);if(!u&&s&&(n=!0,u=await f.find(s,o)),!u)return kt;try{n&&(e.statusCode=c),e.setHeader("content-type",u.mime??nn(m(u.canonicalPath))),u.encoding&&"identity"!==u.encoding&&e.setHeader("content-encoding",u.encoding);const r=f.vary;if(r){const t=e.getHeader("vary")??"";e.setHeader("vary",(t?t+", ":"")+r)}await i(t,e,u,n),await Oi(t,e,u.handle,u.stats)}finally{u.handle.close().catch(()=>{})}}}};function Hi(t,e,n){e.setHeader("etag",He(e.getHeader("content-encoding"),n.stats)),e.setHeader("last-modified",n.stats.mtime.toUTCString())}class qi extends Error{constructor(t,{message:e,statusMessage:n,...i}={}){super(e,i),this.statusCode=0|t,this.statusMessage=n??"",this.name=`WebSocketError(${this.statusCode} ${this.statusMessage})`}static NORMAL_CLOSURE=1e3;static GOING_AWAY=1001;static UNSUPPORTED_DATA=1003;static POLICY_VIOLATION=1008;static MESSAGE_TOO_BIG=1009;static INTERNAL_SERVER_ERROR=1011;static SERVICE_RESTART=1012;static TRY_AGAIN_LATER=1013;static BAD_GATEWAY=1014}function Li(t,{softCloseStatusCode:e=qi.GOING_AWAY,...n}={}){const i=(i,r,o)=>new Promise((s,c)=>{const a=new t({...n,noServer:!0,clientTracking:!1});a.once("wsClientError",c),a.handleUpgrade(i,r,o,t=>{a.off("wsClientError",c),s({return:t,onError:e=>{const n=V(e,qi);if(n)return void t.close(n.statusCode,n.statusMessage);const i=V(e,oe)??new oe(500),r=i.statusCode>=500?qi.INTERNAL_SERVER_ERROR:4e3+i.statusCode;t.close(r,i.statusMessage)},softCloseHandler:n=>t.close(e,n)})})});return t=>Nt(t,i)}class zi{constructor(t,e){this.data=t,this.isBinary=e}get text(){if(this.isBinary)throw new qi(qi.UNSUPPORTED_DATA,{statusMessage:"expected text"});return this.data.toString("utf-8")}get binary(){if(!this.isBinary)throw new qi(qi.UNSUPPORTED_DATA,{statusMessage:"expected binary"});return this.data}}class Wi{constructor(t,{limit:e=-1,signal:n}={}){this.en=new J;const i=e=>{t.off("message",o),t.off("close",r),this.en.close(new Error(e))},r=()=>i("connection closed"),o=(t,n)=>{void 0!==n?this.en.push(new zi(t,n)):"string"==typeof t?this.en.push(new zi(Buffer.from(t,"utf-8"),!1)):this.en.push(new zi(t,!0)),e>0&&0===--e&&this.detach()};this.detach=()=>{},n?.aborted?this.en.close(n.reason):2===t.readyState||3===t.readyState?this.en.close(new Error("connection closed")):(t.on("message",o),t.on("close",r),n?.addEventListener("abort",()=>i("signal aborted")),this.detach=()=>i("WebSocket listener detached"))}next(t){return this.en.shift(t)}[Symbol.asyncIterator](){return this.en[Symbol.asyncIterator]()}}function Gi(t,{timeout:e,signal:n}={}){const i=new Wi(t,{limit:1,signal:n});return i.next(e).finally(()=>i.detach())}function Ji(t){const e=at(t);return"GET"===t.method&&(e.I?.has("websocket")??!1)}const Vi=t=>t.headers.origin??lt(t.headers["sec-websocket-origin"]),Zi=(t,e=5e3)=>async n=>{if(!Ji(n))return;const i=await t(n);let r;try{r=await Gi(i,{timeout:e})}catch(t){if((i.readyState??0)>=2)throw St;throw new qi(qi.POLICY_VIOLATION,{statusMessage:"timeout waiting for authentication token",cause:t})}if(r.isBinary)throw new qi(qi.UNSUPPORTED_DATA,{statusMessage:"authentication token must be sent as text"});return r.data.toString("utf-8")};export{J as BlockingQueue,kt as CONTINUE,hn as FileFinder,oe as HTTPError,$t as NEXT_ROUTE,At as NEXT_ROUTER,Ne as Property,G as Queue,Kt as Router,St as STOP,Bi as ServerSentEvents,de as WebListener,qi as WebSocketError,zi as WebSocketMessage,Wi as WebSocketMessages,pn as acceptBody,Nt as acceptUpgrade,_t as addTeardown,zt as anyHandler,Cn as checkIfModified,Un as checkIfRange,Ce as clearProperty,Mn as compareETag,rn as compressFileOffline,on as compressFilesInDir,Jt as conditionalErrorHandler,tn as decompressMime,Et as defer,an as emitError,Wt as errorHandler,ji as fileServer,V as findCause,qe as generateStrongETag,He as generateWeakETag,Tt as getAbortSignal,jt as getAbsolutePath,Z as getAddressURL,be as getAuthorization,Hn as getBodyJson,In as getBodyStream,jn as getBodyText,Bn as getBodyTextStream,ve as getCharset,yi as getFormData,mi as getFormFields,Ee as getIfRange,nn as getMime,Bt as getPathParameter,It as getPathParameters,Fe as getProperty,ye as getQuery,_e as getRange,bi as getRemainingPathComponents,pe as getSearch,me as getSearchParams,Rn as getTextDecoder,Pn as getTextDecoderStream,Vi as getWebSocketOrigin,De as hasAuthScope,mt as isSoftClosed,Ji as isWebSocketRequest,fn as jsonErrorHandler,Li as makeAcceptWebSocket,q as makeAddressTester,gn as makeGetClient,Oe as makeMemo,Je as makeNegotiator,wn as makeTempFileStorage,Zi as makeWebSocketFallbackTokenFetcher,Ge as negotiateEncoding,Gi as nextWebSocketMessage,H as parseAddress,mn as proxy,$e as readHTTPDateSeconds,xe as readHTTPInteger,ke as readHTTPKeyValues,Se as readHTTPQualityValues,Te as readHTTPUnquotedCommaSeparated,Qe as readMimeTypes,Nn as registerCharset,en as registerMime,On as registerUTF32,En as removeForwarded,_n as replaceForwarded,qt as requestHandler,Ie as requireAuthScope,Me as requireBearerAuth,Ke as resetMime,Ht as restoreAbsolutePath,Tn as sanitiseAndAppendForwarded,Ti as sendCSVStream,Oi as sendFile,Ri as sendJSON,Pi as sendJSONStream,Ai as sendRanges,Hi as setDefaultCacheHeaders,Pe as setProperty,wt as setSoftCloseHandler,xn as simpleAppendForwarded,$i as simplifyRange,ae as toListeners,Gt as typedErrorHandler,Lt as upgradeHandler};
|
|
1
|
+
import{isIPv4 as t,isIPv6 as e}from"node:net";import{STATUS_CODES as n,createServer as i,Agent as r,request as o,ServerResponse as s}from"node:http";import{createReadStream as c,constants as a,createWriteStream as f,openAsBlob as u}from"node:fs";import{createHash as h,randomUUID as l}from"node:crypto";import{pipeline as d}from"node:stream/promises";import w from"node:zlib";import{promisify as p}from"node:util";import{extname as m,join as y,dirname as g,basename as b,sep as v,resolve as E}from"node:path";import{readFile as _,writeFile as T,stat as x,readdir as S,realpath as $,open as k,mkdtemp as N,rm as O}from"node:fs/promises";import{tmpdir as A,platform as R}from"node:os";import{Agent as P,request as F}from"node:https";import{TransformStream as C,TextDecoderStream as U,DecompressionStream as M,ReadableStream as B}from"node:stream/web";import{Readable as D,Duplex as I,Writable as j}from"node:stream";function H(n){if(!n||"unknown"===n)return;const i=/^((?:\d{1,3}\.){3}\d{1,3})(?::(\d+))?$/.exec(n);if(i?.[1]&&t(i[1]))return{type:"IPv4",ip:i[1],port:i[2]?Number.parseInt(i[2]):void 0};const r=/^\[([\da-fA-F:]+)\](?::(\d+))?$|^([\da-fA-F:]+)$/.exec(n);if(r?.[1]&&e(r[1]))return{type:"IPv6",ip:r[1].toLowerCase(),port:r[2]?Number.parseInt(r[2]):void 0};if(r?.[3]&&e(r[3]))return{type:"IPv6",ip:r[3].toLowerCase(),port:void 0};const o=/^(.*?):(\d+)$/i.exec(n);return o?.[2]?{type:"alias",ip:o[1],port:Number.parseInt(o[2])}:{type:"alias",ip:n,port:void 0}}function q(t){const e=new Set,n=[],i=[];for(const r of t){const t=/^((?:\d{1,3}\.){3}\d{1,3})(?:\/(\d+))?$/.exec(r);if(t?.[1]){const e=t[2]?Number.parseInt(t[2]):32,i=e<32?4294967295>>>e:0;n.push([L(t[1])|i,i]);continue}const o=/^\[?([\da-fA-F:]+)\]?(?:\/(\d+))?$/.exec(r);if(o?.[1]){const t=z(o[1]),e=o[2]?J>>BigInt(Number.parseInt(o[2])):0n;i.push([t|e,e]);continue}e.add(r)}return t=>{switch(t?.type){case"alias":return e.has(t.ip);case"IPv4":const r=L(t.ip);return n.some(([t,e])=>(r|e)===t);case"IPv6":const o=z(t.ip);return i.some(([t,e])=>(o|e)===t);default:return!1}}}const J=/*@__PURE__*/BigInt("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");function L(t){const e=t.split(".").map(Number);return(e[0]<<24|e[1]<<16|e[2]<<8|e[3])>>>0}function z(t){const e=t.split(":").map(t=>t?Number.parseInt(t,16):-1);let n=0n;for(const t of e)t<0?n<<=16n*BigInt(9-e.length):n=n<<16n|BigInt(t);return n}class W{constructor(t){const e={t:null,i:null};this.o=e,this.u=e,void 0!==t&&this.push(t)}isEmpty(){return!this.o.i}clear(){this.o.i=null,this.o.t=null,this.u=this.o}push(t){const e={t,i:null};this.u.i=e,this.u=e}shift(){if(!this.o.i)return null;this.o=this.o.i;const t=this.o.t;return this.o.t=null,t}remove(t){for(let e=this.o;e.i;e=e.i)if(e.i.t===t){e.i=e.i.i;break}}[Symbol.iterator](){return{next:()=>{if(!this.o.i)return{value:null,done:!0};this.o=this.o.i;const t=this.o.t;return this.o.t=null,{value:t,done:!1}}}}}class G{constructor(){this.h=new W,this.l=new W,this.m=0}push(t){if(this.m)return;const e=this.l.shift();e?(e.v&&clearTimeout(e.v),e._(t)):this.h.push(t)}shift(t){return this.h.isEmpty()?this.m?Promise.reject(this.T):new Promise((e,n)=>{const i={_:e,S:n,v:null};this.l.push(i),void 0!==t&&(i.v=setTimeout(()=>{this.l.remove(i),n(new Error(`timeout after ${t}ms`))},t))}):Promise.resolve(this.h.shift())}$(t){this.T=t;for(const e of this.l)e.S(t),e.v&&clearTimeout(e.v)}close(t){this.m||(this.m=1,this.$(t))}fail(t){this.m||(this.m=2,this.$(t))}[Symbol.asyncIterator](){return{next:()=>this.shift().then(t=>({value:t,done:!1}),t=>{if(2===this.m)throw t;return{value:null,done:!0}})}}}function V(t,e){if(t instanceof e)return t;if(t&&"object"==typeof t){if("cause"in t)return V(t.cause,e);if("error"in t)return V(t.error,e)}}function Z(t,e="http"){if(!t)throw new TypeError("no address");if("string"==typeof t)return t;if("IPv4"===t.family)return`${e}://${t.address}:${t.port}`;if("IPv6"===t.family)return`${e}://[${t.address}]:${t.port}`;throw new TypeError(`unknown address family: ${t.family}`)}const X=/*@__PURE__*/Buffer.alloc(0),Y=t=>new URL("http://localhost"+(t.url??"/"));class K extends Error{constructor(t,e,n){super(n??""),this.error=t,this.suppressed=e}}const Q=globalThis.SuppressedError??K;class tt{constructor(){this.k=!1}N(t){this.k?t!==this.O&&(this.O=new Q(t,this.O)):(this.O=t,this.k=!0)}A(){this.k=!1,this.O=void 0}}const et=new WeakMap;function nt(t,e,n){const i=et.get(t);if(i)return i;const r=Y(t),o={R:t,P:r,F:decodeURIComponent(r.pathname),C:new AbortController,U:e,M:[],B:[],D:n?ot(t):null};return et.set(t,o),o}function it(t,e,n){e||(t.D=null),t.I=n;const i=async()=>{t.C.abort(n.j.writableEnded?"complete":"client abort");const e=new tt;await rt(t.M,e,t),await rt(t.B,e,t,()=>{t.H=async e=>{try{await e()}catch(e){t.U(e,"tearing down",t.R)}}}),e.k&&t.U(e.O,"tearing down",t.R)};return n.j.closed?i():n.j.once("close",i),t}async function rt(t,e,n,i){for(;n.J;)await n.J;const r=(async()=>{for(;;){const n=t.pop();if(!n)return void i?.();try{await n()}catch(t){e.N(t)}}})().then(()=>{n.J===r&&(n.J=void 0)});n.J=r,await r}function ot(t){return new Set(t.headers.upgrade?.split(",").map(t=>t.trim().toLowerCase())??[])}const st=t=>et.get(t),ct=t=>et.delete(t);function at(t){const e=st(t);if(!e)throw new RangeError("unknown request");return e}function ft(t,e,n=ft){throw t.code=e,Error.captureStackTrace(t,n),t}class ut{constructor(t){this.L=t,this.W=Object.create(null),this.G=!1}get headersSent(){return this.G}writeHead(t,e=n[t]??"-"){return this.G&&ft(new Error("Cannot write headers after they are sent to the client"),"ERR_HTTP_HEADERS_SENT"),this.L.write([`HTTP/1.1 ${t} ${dt(e)}`,...ht(this.W),"",""].join("\r\n"),"ascii"),this.G=!0,this}write(t,e="utf-8",n){return this.L.write(t,e,n)}end(t,e="utf-8",n){return this.L.end(t,e,n),this}setHeader(t,e){const n=t.toLowerCase();return this.W[n]="string"==typeof e||"number"==typeof e?e:[...e],this}setHeaders(t){for(const[e,n]of t)this.setHeader(e,n);return this}}function ht(t){const e=[];for(const[n,i]of Object.entries(t)){const t=lt(i);t&&e.push(`${dt(n)}: ${dt(t)}`)}return e}const lt=t=>"string"==typeof t?t:"number"==typeof t?String(t):t?t.join(", "):"",dt=t=>t.replaceAll(/[^ \t!-~]/g,"");function wt(t,e){const n=st(t);n&&pt(n,e)}function pt(t,e){t.V=e;const n=t.Z;n&&queueMicrotask(()=>vt(e,n,t))}const mt=t=>Boolean(st(t)?.Z);function yt(t,e,n){if(!t.Z){if(t.I&&!t.D){const e=t.I.j;e.headersSent||e.hasHeader("connection")||e.setHeader("connection","close")}t.I?.j.once("close",()=>t.R.socket.destroy()),t.Z={X:e,U:n},vt(t.V,t.Z,t),bt(t)}}function gt(t){if(t.I){if(t.D){if(!t.Y&&t.I.j.writable){const e=new ut(t.I.j);e.setHeader("connection","close"),e.writeHead(503)}}else{const e=t.I.j;e.headersSent||(e.hasHeader("connection")||e.setHeader("connection","close"),e.writeHead(503))}t.I.j.end(()=>t.R.socket.destroy())}else t.R.socket.destroy()}function bt(t){if(clearTimeout(t.K),!t.tt||t.H)return;const e=Date.now();if(e>=t.tt)return void gt(t);let n=t.tt;t.et&&!t.Z&&(e<t.et.nt?n=t.et.nt:(t.Z=t.et,vt(t.V,t.Z,t))),void 0===t.K&&t.B.push(()=>clearTimeout(t.K)),t.K=setTimeout(()=>bt(t),n-e)}async function vt(t,e,n){try{await(t?.(e.X))}catch(t){e.U(t,"soft closing",n.R),gt(n)}}const Et=(t,e)=>{const n=at(t);n.H?n.H(e):n.M.push(e)},_t=(t,e)=>{const n=at(t);n.H?n.H(e):n.B.push(e)},Tt=t=>at(t).C.signal;class xt extends Error{}const St=new xt("STOP"),$t=new xt("CONTINUE"),kt=new xt("NEXT_ROUTE"),Nt=new xt("NEXT_ROUTER");async function Ot(t,e){const n=at(t);if(!n.I)throw new TypeError("cannot call acceptUpgrade from shouldUpgrade");if(!n.D)throw new TypeError("not an upgrade request");if(3===n.Y)throw new TypeError("upgrade already delegated");if(2===n.Y)return n.it;const i=n.I.j;if(!i.readable||!i.writable)throw St;n.Y=1;const r=await e(t,i,n.I.o);return n.I.o=X,n.rt=r.onError,r.softCloseHandler&&pt(n,r.softCloseHandler),n.Y=2,n.it=r.return,r.return}const At=RegExp.escape??(t=>t.replaceAll(/[^a-zA-Z0-9_ ]/g,t=>"\\u"+t.charCodeAt(0).toString(16).padStart(4,"0"))),Rt=t=>t,Pt=t=>void 0===t?void 0:""===t?[]:t.split("/"),Ft=t=>void 0===t?void 0:""===t?[]:t.split("/").filter(t=>t);function Ct(t){const e={},n=new Map;for(const[i,r]of Object.entries(t))e[i]=!1,n.set(r,i);return t=>{const i={...e};for(let e=0;e<t.length;++e){const r=n.get(t[e]);if(!r)return[i,t.substring(e)];i[r]=!0}return[i,""]}}const Ut=/*@__PURE__*/Ct({ot:"i",st:"!"}),Mt=Object.freeze({});function Bt(t,e,n){const i=t.R.url,r=t.F,o=t.ct??Mt;return t.R.url=encodeURIComponent(e).replaceAll(/%2F/g,"/")+t.P.search,t.F=e,n.length>0&&(t.ct=Object.freeze(Object.fromEntries([...Object.entries(o),...n]))),()=>{t.R.url=i,t.F=r,t.ct=o}}function Dt(t){return st(t)?.ct??Mt}function It(t,e){return Dt(t)[e]}function jt(t){const e=st(t);return e?e.P.pathname+e.P.search:t.url??"/"}function Ht(t){const e=st(t);e&&(t.url=e.P.pathname+e.P.search)}const qt=t=>"function"==typeof t?{handleRequest:t}:t,Jt=(t,e)=>"function"==typeof t?{handleUpgrade:t,shouldUpgrade:e}:{shouldUpgrade:e,...t},Lt=(t,e=Xt)=>({handleRequest:t,handleUpgrade:t,shouldUpgrade:e}),zt=t=>"function"==typeof t?{handleError:t}:t,Wt=(t,e)=>Gt(e=>e instanceof t,e),Gt=(t,e)=>({handleError:(n,i,r)=>{if(r.response&&t(n))return e(n,i,r.response);throw n},shouldHandleError:(e,n,i)=>Boolean(i.response)&&t(e)}),Vt=t=>"function"==typeof t?{handleRequest:t}:t,Zt=t=>"function"==typeof t?{handleUpgrade:t}:t,Xt=()=>!1,Yt=Symbol("http");class Kt{constructor(){this.ft=[],this.ut=[]}N(t,e,n,i,r){const o=n?((t,e)=>{const n=["^"],i=[],r=/[{}]|\/+|\\(.)|[:*]([a-zA-Z0-9_]*)/g,[{ot:o,st:s},c]=Ut(t);if("/"!==c[0])throw new TypeError("path must begin with '/' or flags");let a=0,f=0;for(const t of c.matchAll(r)){t.index>a&&n.push(At(c.substring(a,t.index)));const e=t[0];if("{"===e)n.push("(?:"),++f;else if("}"===e){if(0===f)throw new TypeError(`unbalanced optional braces in path at ${t.index}`);--f,n.push(")?")}else if("/"===e[0])n.push(e),s||n.push("+");else if("\\"===e[0])n.push(At(t[1]));else{const r=e[0],o=t[2];if(!o)throw new TypeError(`unnamed parameter or unescaped '${r}' at ${t.index}`);"*"===r?(n.push("(.*?)"),i.push({ht:o,lt:s?Pt:Ft})):(n.push("([^/]+?)"),i.push({ht:o,lt:Rt}))}a=t.index+e.length}if(a<c.length&&n.push(At(c.substring(a))),f>0)throw new TypeError("unbalanced optional braces in path");return e&&(n.push("(?:"),s?n.push("(?:(?<=/)|/)"):n.push("(?:/+|(?<=/))"),n.push("(?<rest>.*))?")),n.push("$"),{dt:new RegExp(n.join(""),o?"i":""),wt:i}})(n,i):{dt:null,wt:[]};return this.ft.push({yt:t,gt:"string"==typeof e?e.toLowerCase():e,bt:o.dt,vt:o.wt,Et:r}),this}use(...t){return this.N(null,null,null,!0,t.map(Vt))}mount(t,...e){return this.N(null,null,t,!0,e.map(Vt))}within(t,e){const n=new Kt;return e(n),this.mount(t,n)}at(t,...e){return this.N(null,null,t,!1,e.map(Vt))}onRequest(t,e,...n){return this.N(te(t),Yt,e,!1,n.map(Vt))}onUpgrade(t,e,n,...i){return this.N(te(t),e,n,!1,i.map(Zt))}onError(...t){return this.N(null,null,null,!0,t.map(zt))}onReturn(...t){return this.ut.push(...t),this}on(t,...e){const n=/^([A-Z]+) (\/.*)$/.exec(t);if(!n)throw new TypeError("invalid method + path spec: "+JSON.stringify(t));return this.N(n[1],Yt,n[2],!1,e.map(Vt))}get=(t,...e)=>this.N(Qt,Yt,t,!1,e.map(Vt));delete=(...t)=>this.onRequest("DELETE",...t);getOnly=(...t)=>this.onRequest("GET",...t);head=(...t)=>this.onRequest("HEAD",...t);options=(...t)=>this.onRequest("OPTIONS",...t);patch=(...t)=>this.onRequest("PATCH",...t);post=(...t)=>this.onRequest("POST",...t);put=(...t)=>this.onRequest("PUT",...t);ws=(...t)=>this.onUpgrade("GET","websocket",...t);async handleRequest(t){return this._t(t,new tt)}async handleUpgrade(t){return this._t(t,new tt)}async handleError(t,e){const n=new tt;return n.N(t),this._t(e,n)}shouldUpgrade(t){return this.Tt(at(t))}Tt(t){for(const e of this.ft){const n=ee(t,e);if(!n)continue;let i=()=>{};if(!0!==n)try{i=Bt(t,n.xt,[])}catch{continue}try{for(const n of e.Et)if(re(n,t))return!0}finally{i()}}return!1}async _t(t,e){const n=at(t),i=await this.St(n,e);if(e.k)throw e.O;return i}async St(t,e){for(const n of this.ft){const i=ee(t,n);if(!i)continue;let r=()=>{};if(!0!==i)try{const e=i.$t();r=Bt(t,i.xt,e)}catch(t){e.N(t);continue}try{const i=await ne(t,n.Et,this.ut,e);if(i===Nt)break;if(i===kt)continue;return i}finally{r()}}return $t}}const Qt=new Set(["HEAD","GET"]),te=t=>t?"string"==typeof t?t:new Set(t):null;function ee(t,e){if("string"==typeof e.yt){if(e.yt!==t.R.method)return!1}else if(null!==e.yt&&!e.yt.has(t.R.method??""))return!1;if(e.gt===Yt){if(t.D)return!1}else if(null!==e.gt&&!t.D?.has(e.gt))return!1;if(null===e.bt)return!0;const n=e.bt.exec(t.F);return!!n&&{xt:"/"+(n.groups?.rest??""),$t:()=>e.vt.map((t,e)=>[t.ht,t.lt(n[e+1])])}}async function ne(t,e,n,i){for(const r of e){let e=await ie(r,t,i);if(e!==$t){if(!t.D&&!(e instanceof xt)&&n.length)try{const i="object"==typeof e?e:void 0,r=t.R,o=t.I.j;for(const t of n)await t(i,r,o)}catch(t){i.N(t);continue}return e}}return kt}async function ie(t,e,n){if(t instanceof Kt)return t.St(e,n);let i=$t;try{if(n.k){if(t.handleError){const r=n.O,o=e.D?{socket:e.I.j,head:e.I.o,hasUpgraded:Boolean(e.Y)}:{response:e.I.j};t.shouldHandleError&&!t.shouldHandleError(r,e.R,o)||(n.A(),i=await t.handleError(r,e.R,o))}}else if(e.D){if(t.handleUpgrade){const n=e.I;i=await t.handleUpgrade(e.R,n.j,n.o)}}else t.handleRequest&&(i=await t.handleRequest(e.R,e.I.j))}catch(t){t instanceof xt?i=t:n.N(t)}finally{e.M.length&&await((t,e)=>rt(t.M,e,t))(e,n)}return i===St?void 0:i}function re(t,e){if(t instanceof Kt)return t.Tt(e);if(!t.shouldUpgrade)return Boolean(t.handleUpgrade);try{return t.shouldUpgrade(e.R)}catch(t){return e.U(t,"checking should upgrade",e.R),!1}}class oe extends Error{constructor(t,{message:e,statusMessage:i,headers:r,body:o,...s}={}){super(e??o,s),this.statusCode=0|t,this.statusMessage=i??n[this.statusCode]??"-",this.headers=(t=>{if(!t||t instanceof Headers||Array.isArray(t))return new Headers(t);const e=t instanceof Map?[...t.entries()]:Object.entries(t);return new Headers(e.map(([t,e])=>[t,lt(e)]).filter(([t,e])=>e))})(r),this.body=o??"",this.name=`HTTPError(${this.statusCode} ${this.statusMessage})`}}const se=(t,e,n)=>{const i=ce(n);if(!i)return;const r=V(t,oe)??new oe(500);i.setHeader("content-type","text/plain; charset=utf-8"),i.setHeaders(r.headers),i.setHeader("content-length",String(Buffer.byteLength(r.body,"utf-8"))),n.response||i.setHeader("connection","close"),i.writeHead(r.statusCode,r.statusMessage),i.end(r.body,"utf-8")};function ce(t){if(t.response){const e=t.response;return e.headersSent?void e.end():e}const e=t.socket;if(!t.hasUpgraded&&e.writable)return e.addListener("finish",()=>e.destroy()),new ut(e);e.destroy()}function ae(t,{onError:e=fe,socketCloseTimeout:n=500}={}){let i=0,r="",o=e;const s=[],c=new Set,a=()=>{const t=[...s];s.length=0;for(const e of t)e()},f=t=>{t&&(c.size?s.push(t):setImmediate(t))},u=t=>{c.add(t),t.B.push(()=>{c.delete(t),!c.size&&s.length&&setImmediate(a)})};return{request:async(n,s)=>{let c;try{c=nt(n,e,!1)}catch(t){return e(t,"parsing request",n),void se(new oe(400),0,{response:s})}if(it(c,!1,{j:s}),u(c),1===i)yt(c,r,o);else if(2===i)return gt(c),void ct(n);const a=new tt,f=await ie(t,c,a);a.k||f!==$t&&f!==kt&&f!==Nt||a.N(new oe(404)),a.k&&(e(a.O,"handling request",n),se(a.O,0,{response:s}),ct(n))},upgrade:async(s,c,a)=>{let f;c.once("finish",()=>{const t=setTimeout(()=>c.destroy(),n);c.once("close",()=>clearTimeout(t))});try{f=nt(s,e,!0)}catch(t){return e(t,"parsing upgrade",s),void se(new oe(400),0,{socket:c,hasUpgraded:!1})}if(it(f,!0,{j:c,o:a}),a=X,u(f),1===i)yt(f,r,o);else if(2===i)return gt(f),void ct(s);const h=new tt,l=await ie(t,f,h);h.k||l!==$t&&l!==kt&&l!==Nt||(console.warn(`Upgrade ${s.headers.upgrade} request for ${s.url} fell-through. This probably means you need to add shouldUpgrade to one of your upgrade handlers, or if this is intentional, explicitly reject the request (throw new HTTPError(404)) instead of using CONTINUE.`),h.N(new oe(404))),h.k&&(e(h.O,"handling upgrade",s),f.rt?f.rt(h.O):se(h.O,0,{socket:c,head:f.I?.o??X,hasUpgraded:Boolean(f.Y)}),ct(s))},shouldUpgrade:n=>{try{const i=nt(n,e,!0);return re(t,i)}catch{return!1}},clientError:(t,n)=>{const i=n.kt,r=t.code;n.writable&&!i?.headersSent&&n.end(he.get(r)??le),n.destroy(t),"HPE_INVALID_EOF_STATE"===r||e(t,"initialising request",void 0)},softClose(t,e,n){if(i<1){i=1,r=t,o=e;for(const n of c)yt(n,t,e)}f(n)},hardClose(t){if(i<2){i=2;for(const t of c)gt(t)}f(t)},countConnections:()=>c.size}}const fe=(t,e,n)=>{(V(t,oe)?.statusCode??500)>=500&&console.error("%s",`unhandled error while ${e} ${n?.url??"(no request information)"}:`,t)},ue=t=>Buffer.from(`HTTP/1.1 ${t} ${n[t]}\r\nConnection: close\r\n\r\n`),he=/*@__PURE__*/new Map([["HPE_HEADER_OVERFLOW",/*@__PURE__*/ue(431)],["HPE_CHUNK_EXTENSIONS_OVERFLOW",/*@__PURE__*/ue(413)],["ERR_HTTP_REQUEST_TIMEOUT",/*@__PURE__*/ue(408)]]),le=/*@__PURE__*/ue(400);class de extends EventTarget{constructor(t){super(),this.Nt=t}attach(t,e={}){const n=(e,n,i)=>{const r={server:t,error:e,context:n,request:i};this.dispatchEvent(new CustomEvent("error",{detail:r,cancelable:!0}))&&fe(e,n,i)},i=ae(this.Nt,{...e,onError:n});!1===e.autoContinue&&t.addListener("checkContinue",i.request),!1===e.rejectNonStandardExpect&&t.addListener("checkExpectation",i.request),t.addListener("request",i.request),t.addListener("upgrade",i.upgrade);const r=t.shouldUpgradeCallback??(()=>!1);!1!==e.overrideShouldUpgradeCallback&&(t.shouldUpgradeCallback=i.shouldUpgrade),t.addListener("clientError",i.clientError);let o=()=>{o=void 0,t.removeListener("checkContinue",i.request),t.removeListener("checkExpectation",i.request),t.removeListener("request",i.request),t.removeListener("upgrade",i.upgrade),t.shouldUpgradeCallback===i.shouldUpgrade&&(t.shouldUpgradeCallback=r),t.removeListener("clientError",i.clientError)};return(t="",e=-1,r=!1,s)=>{if(r||o?.(),e>0){const r=setTimeout(()=>{o?.(),i.hardClose()},e);i.softClose(t,n,()=>{o?.(),clearTimeout(r),s?.()})}else 0===e?(o?.(),i.hardClose(s)):(o?.(),s&&setImmediate(s));return i}}createServer(t={}){t.shouldUpgradeCallback&&(t={overrideShouldUpgradeCallback:!1,...t});const e=i(t),n=this.attach(e,t),r=Object.assign(e,{closeWithTimeout:(t,i)=>new Promise(r=>n(t,i,!0,()=>{e.close(()=>r()),e.closeAllConnections()}))});return r}listen(t,e,n={}){const i=this.createServer(n);return n.socketTimeout&&i.setTimeout(n.socketTimeout),new Promise((r,o)=>{i.once("error",o),i.listen(t,e,n.backlog??511,()=>{i.off("error",o),r(i)})})}}const we=t=>st(t)?.P??Y(t),pe=t=>we(t).search,me=t=>new URLSearchParams(we(t).searchParams),ye=(t,e)=>we(t).searchParams.get(e);function ge(t,e){const n=t.indexOf(e);return-1===n?[t]:[t.substring(0,n),t.substring(n+e.length)]}function be(t){const e=t.headers.authorization;if(!e)return;const[n,i]=ge(e," ");return void 0!==i?[n.trim().toLowerCase(),i.trim()]:void 0}function ve(t){const e=/^text\/.*;\s*charset=([^;]+)/i.exec(t.headers["content-type"]??"");return e?.[1]?.trim().toLowerCase()??void 0}function Ee(t){const e=t.headers["if-range"];return e&&"string"==typeof e?/^("|W\/")/.test(e)?{etag:[e]}:{modifiedSeconds:ke(e)}:{}}function _e(t,e,{maxRanges:n=10,maxNonSequential:i=2,maxWithOverlap:r=2}={}){const o=t.headers.range;if(!o||0===e)return;const[s,c]=ge(o,"=");if("bytes"!==s||!c)return;const a=new oe(416,{headers:{"content-range":`bytes */${e}`}}),f=t=>{const e=xe(t);if(void 0===e)throw a;return e},u=[];for(const t of c.split(",")){const[i,r]=ge(t.trim(),"-");if(void 0===r)throw a;let o;if(i)o={start:f(i),end:r?Math.min(f(r),e-1):e-1};else{if(!r)throw a;o={start:Math.max(e-f(r),0),end:e-1}}if(!(o.start>=e)){if(o.end<o.start||u.length>=n)throw a;u.push(o)}}if(!u.length)throw a;if(u.length>i)for(let t=0;t<u.length-1;++t)if(u[t].start>u[t+1].start)throw a;if(u.length>r)for(let t=1;t<u.length;++t){const e=u[t];for(let n=0;n<t;++n){const t=u[n];if(e.end>=t.start&&t.end>=e.start)throw a}}return{ranges:u,totalSize:e}}function Te(t){if(void 0!==t)return"number"==typeof t?[String(t)]:t.length?"string"==typeof t?t.split(",").map(t=>t.trim()):t.flatMap(t=>t.split(",").map(t=>t.trim())):[]}function xe(t){if(t&&/^\s*-?\d+\s*$/.test(t))return Number.parseInt(t,10)}function Se(t){if(t)return t.split(",").map(t=>{const[e,...n]=t.split(";"),i=new Map(n.map(t=>{const[e,n]=ge(t,"=");return[e.trim(),n?.trim()??""]})),r=e.trim(),o="*/*"===r||"*"===r?0:r.endsWith("/*")?1:2,s=Math.max(0,Math.min(1,Number.parseFloat(i.get("q")??"1")));return{name:r,specifiers:i,specificity:o,q:s}})}function $e(t){const e=new Map,n=/\s*([^=]+)=([^";]*?|"(?:[^\\"]|\\.)*")\s*(?:;|$)/y;for(;n.lastIndex<t.length;){const i=n.exec(t);if(!i)throw new oe(400,{body:"invalid HTTP key values"});const r=i[1].toLowerCase();let o=i[2];'"'===o[0]&&(o=o.substring(1,o.length-1).replaceAll(/\\(.)/g,(t,e)=>e)),e.set(r,o)}return e}function ke(t){if("string"!=typeof t)return;const e=Date.parse(t);return Number.isNaN(e)?void 0:e/1e3|0}const Ne=t=>"function"==typeof t?t:()=>t;class Oe{constructor(t=Ue){this.Ot=Ne(t)}set(t,e){Pe(t,this,e)}get(t){return Fe(t,this)}clear(t){Ce(t,this)}withValue(t){return Lt(e=>(Pe(e,this,t),$t))}}const Ae=(t,...e)=>{const n={Ot:n=>t(n,...e)};return t=>Fe(t,n)};function Re(t){return t.At||(t.At=new Map),t.At}function Pe(t,e,n){Re(at(t)).set(e,n)}function Fe(t,e){const n=st(t);if(!n)return e.Ot(t);const i=Re(n);if(i.has(e))return i.get(e);const r=e.Ot(t);return i.set(e,r),r}function Ce(t,e){const n=st(t);n?.At?.delete(e)}const Ue=()=>{throw new Error("property has not been set")};function Me({realm:t,extractAndValidateToken:e,fallbackTokenFetcher:n,closeOnExpiry:i=!0,softCloseBufferTime:r=0,onSoftCloseError:o}){const s=Ne(t);return{handler:Lt(async t=>{const c=Date.now(),a=await s(t),f={"www-authenticate":`Bearer realm="${a}"`},u=be(t),h="bearer"===u?.[0]?u[1]:await(n?.(t));if(!h)throw new oe(401,{headers:f,body:"no token provided"});let l;try{l=await e(h,a,t)}catch(t){throw new oe(401,{headers:f,body:"invalid token",cause:t})}if(!l)throw new oe(401,{headers:f,body:"invalid token"});if("object"==typeof l){if("nbf"in l&&"number"==typeof l.nbf&&c<1e3*l.nbf)throw new oe(401,{headers:f,body:"token not valid yet"});if("exp"in l&&"number"==typeof l.exp){const e=1e3*l.exp;if(c>=e-r)throw new oe(401,{headers:f,body:"token expired"});i&&((t,e,n,i=0,r)=>{const o=at(t),s=n-Math.max(i,0),c=o.tt??Number.POSITIVE_INFINITY,a=o.et?.nt??c;s>=a&&n>=c||(n<c&&(o.tt=n),s<a&&(o.et={nt:s,X:e,U:r??o.U}),bt(o))})(t,"token expired",e,r,o)}}return Ie.set(t,{Rt:a,Pt:!0,Ft:l,Ct:je(l)}),$t}),getTokenData:t=>{const e=Ie.get(t);if(!e.Pt)throw new TypeError("cannot use getTokenData in an unauthenticated endpoint");return e.Ft}}}const Be=(t,e)=>Ie.get(t).Ct.has(e),De=t=>Lt(e=>{const n=Ie.get(e);if(!n.Ct.has(t))throw new oe(403,{headers:{"www-authenticate":`Bearer realm="${n.Rt}", scope="${t}"`},body:`scope required: ${t}`});return $t}),Ie=/*@__PURE__*/new Oe({Rt:"",Pt:!1,Ft:null,Ct:new Set});function je(t){if(!t||"object"!=typeof t||!("scopes"in t))return new Set;const{scopes:e}=t;return Array.isArray(e)?new Set(e):"string"==typeof e?new Set([e]):e&&"object"==typeof e?new Set(Object.entries(e).filter(([t,e])=>e).map(([t])=>t)):new Set}function He(t,e){const n=`${0|e.mtimeMs} ${e.size} ${t??""}`;return`W/"${h("sha256").update(n).digest("base64").substring(0,12)}"`}async function qe(t){const e=h("sha256");return"string"==typeof t?await d(c(t),e):await d(t.createReadStream({start:0,autoClose:!1}),e),`"sha256-${e.digest("base64")}"`}const Je=(t,e)=>new RegExp(t,(t.unicodeSets?"v":t.unicode?"u":"")+(t.ignoreCase||e?"i":"")),Le={mime:"accept",language:"accept-language",encoding:"accept-encoding"},ze={zstd:"{file}.zst",br:"{file}.br",gzip:"{file}.gz",deflate:"{file}.deflate",identity:"{file}"},We=t=>{return{type:"encoding",options:(e=t,n=ze,Array.isArray(e)?e.map(t=>[t,n[t]]):Object.entries(e)).map(([t,e])=>({match:t,file:e}))};var e,n};function Ge(t,e=10){const n=t.map(t=>({Ut:t.type,Mt:t.options.map(t=>({Bt:t.file,Dt:"string"==typeof t.match?t.match.toLowerCase():Je(t.match,!0),It:t.as??("string"==typeof t.match?t.match:void 0)}))})).filter(t=>t.Mt.length>0);return{options(t,i){let r=e;const o={};return function*t(e,s){const c=n[s];if(!c)return--r,void(yield{filename:e,info:o});const a=new Set,f=(h=i[c.Ut],h?.length?1===h.length?h:[...h].sort(Ve):[]),u=[];var h;for(const t of c.Mt){const e=f.find(e=>"string"==typeof t.Dt?e.name.toLowerCase()===t.Dt:t.Dt.test(e.name));e&&u.push({...e,jt:t})}for(const n of u.sort(Ve)){const i=Ze(e,n.jt.Bt);if(!a.has(i)&&(a.add(i),o[c.Ut]=n.jt.It,yield*t(i,s+1),r<=0))return}o[c.Ut]=void 0,!a.has(e)&&r>0&&(yield*t(e,s+1))}(t,0)},vary:[...new Set(n.map(t=>Le[t.Ut]))].join(" ")}}const Ve=(t,e)=>e.q-t.q||e.specificity-t.specificity;function Ze(t,e){return e.replaceAll(/\{(?:file|base|ext)\}/g,e=>"{file}"===e?t:"{base}"===e?t.replace(/\.[^.]*$/,""):m(t))}const Xe=/*@__PURE__*/tn("bin=application/octet-stream;gz(ip),json,ogg,pdf,wasm,xml,y(a)ml,zip,zst(d)=application/{ext};aac,flac,mid(i),wav(e)=audio/{ext};mp3=audio/mpeg;oga,opus=audio/ogg;otf,ttf,woff,woff2=font/{ext};apng,avif,bmp,gif,heic,heif,jp(e)g,png,tif(f),webp=image/{ext};ico,cur=image/x-icon;svg=image/svg+xml;3mf,obj,stl,u3d=model/{ext};wrl=model/vrml;x3d=model/x3d+xml;x3db=model/x3d+binary;x3dv=model/x3d+vrml;css,csv,htm(l),rtf,vcard=text/{ext};(m)js=text/javascript;md=text/markdown;txt=text/plain;3gp(p),3g(pp)2,mp4,mp(e)g,h264=video/{ext};mov=video/quicktime;ogv=video/ogg");let Ye=/*@__PURE__*/new Map(Xe);function Ke(){Ye=new Map(Xe)}function Qe(t){const e=new Map;for(const n of t.split("\n")){const[t,...i]=n.replaceAll(/\s+/g," ").trim().split(" ");if(!t.startsWith("#"))for(const n of i)e.set(n.toLowerCase(),t)}return e}function tn(t){const e=new Map;for(const n of t.split(/[\n;]/g)){const[t,i,r]=/^ *([^=]+)=(.*)$/.exec(n)??[null,null,""];for(const t of i?.split(",")??[]){const[n,i,o="",s=""]=/^([^(]*)(?:\(([^)]*)\)(.*))?$/.exec(t),c=i+o+s,a=r.replace("{ext}",c);e.set(c.toLowerCase(),a),o&&e.set((i+s).toLowerCase(),a)}}return e}function en(t){for(const[e,n]of t)Ye.set(e.toLowerCase(),n)}function nn(t,e="utf-8"){"."===t[0]&&(t=t.substring(1));const n=Ye.get(t)??"application/octet-stream";return n.startsWith("text/")&&!n.includes("charset=")?`${n}; charset=${e}`:n}async function rn(t,e,n){const i=await _(t),r={file:t,mime:nn(m(t)),rawSize:i.byteLength,bestSize:i.byteLength,created:0};if(r.rawSize<=n)return r;if(["image","video","audio","font"].includes(r.mime.split("/")[0]))return r;for(const o of e){const e=cn.get(o.match),s=y(g(t),Ze(b(t),o.file));if(!e||s===o.file)continue;const c=await e(i);c.byteLength<=r.rawSize-n&&(await T(s,c),r.bestSize=Math.min(r.bestSize,c.byteLength),++r.created)}return r}async function on(t,e,n){const i=[];await sn(t,i);const r=new Set(i);for(const t of r)for(const n of e){const e=y(g(t),Ze(b(t),n.file));e!==t&&r.delete(e)}return Promise.all([...r].map(t=>rn(t,e,n)))}async function sn(t,e){const n=await x(t);if(n.isDirectory())for(const n of await S(t))await sn(y(t,n),e);else n.isFile()&&e.push(t)}const cn=/*@__PURE__*/new Map([["zstd",t=>p(w.zstdCompress)(t)],["br",t=>p(w.brotliCompress)(t,{params:{[w.constants.BROTLI_PARAM_QUALITY]:w.constants.BROTLI_MAX_QUALITY,[w.constants.BROTLI_PARAM_SIZE_HINT]:t.length}})],["gzip",t=>p(w.gzip)(t,{level:w.constants.Z_BEST_COMPRESSION})],["deflate",t=>p(w.deflate)(t)]]),an=(t,e,n)=>{const i=at(t);i.U(e,n??(i.D?"handling upgrade":"handling request"),t)},fn=(t,{onlyIfRequested:e=!0,emitError:n=!0,forceStatus:i,contentType:r="application/json"}={})=>({handleError:(o,s,c)=>{if(c.hasUpgraded||e&&!un(s,r))throw o;n&&an(s,o);const a=ce(c);if(!a)return;const f=V(o,oe)??new oe(500),u=JSON.stringify(t(f));a.setHeaders(f.headers),a.setHeader("content-type",r),a.setHeader("content-length",String(Buffer.byteLength(u,"utf-8"))),c.response||a.setHeader("connection","close"),i?a.writeHead(i):a.writeHead(f.statusCode,f.statusMessage),a.end(u,"utf-8")},shouldHandleError:(t,n,i)=>!i.hasUpgraded&&(!e||un(n,r))}),un=(t,e)=>Se(t.headers.accept)?.some(t=>t.name===e||"application/json"===t.name)??!1;class hn{constructor(t,{subDirectories:e=!0,caseSensitive:n="exact",allowAllDotfiles:i=!1,allowAllTildefiles:r=!1,allowDirectIndexAccess:o=!1,allow:s=[".well-known"],hide:c=[],indexFiles:a=["index.htm","index.html"],implicitSuffixes:f=[],negotiation:u}){this.Ht=t,this.qt=!0===e?Number.POSITIVE_INFINITY:e||0,this.Jt=n,this.Lt=i,this.zt=r,this.Wt=o,this.Gt=a,this.Vt=["",...f],this.Zt=new Set(s.map(t=>this.Xt(t))),this.Yt=new Set,this.Kt=[];for(const t of c)"string"==typeof t?this.Yt.add(this.Xt(t)):this.Kt.push(Je(t,!n));this.Qt=new Set(a.map(t=>this.Xt(t))),u?.length?(this.te=Ge(u),this.vary=this.te.vary):this.vary=""}static async build(t,e){return new hn(await $(t,{encoding:"utf-8"})+v,e)}Xt(t){return"exact"===this.Jt?t:t.toLowerCase()}ee(t){if(this.Zt.has(t))return!0;const e=t.trim();return!(!("~"!==e[0]&&"~"!==e[e.length-1]||this.zt)||"."===e[0]&&!this.Lt||this.Yt.has(e)||this.Kt.some(t=>t.test(e)))}async find(t,e={},n){let i=t.join(v);"force-lowercase"===this.Jt&&(i=i.toLowerCase());let r=E(this.Ht,i);if(!r.startsWith(this.Ht)&&r+v!==this.Ht)return n?.push(`${JSON.stringify(r)} is not inside root ${JSON.stringify(this.Ht)}`),null;let o=null,s=null;for(const t of this.Vt){const e=r+t;if(o=e.substring(this.Ht.length).split(v).filter(t=>t),o.length-1>this.qt)return n?.push(`${JSON.stringify(r)} is nested too deeply (${o.length-1} > ${this.qt})`),null;if(o.some(t=>!this.ee(this.Xt(t))))return n?.push(`${JSON.stringify(r)} is not permitted`),null;const i=o[o.length-1]??"";if(!this.Wt&&this.Qt.has(this.Xt(i))&&!this.Zt.has(this.Xt(i)))return n?.push(`${JSON.stringify(r)} is a hidden index file`),null;if(s=await $(e,{encoding:"utf-8"}).catch(()=>null),s){r=e;break}}if(!s||!o)return n?.push(`file ${JSON.stringify(r)} does not exist`),null;if(this.Xt(s)!==this.Xt(r))return n?.push(`realpath ${JSON.stringify(s)} does not match request ${JSON.stringify(r)}`),null;let c=s,a=await x(s).catch(()=>null);if(!a)return n?.push(`file ${JSON.stringify(s)} does not exist`),null;if(a.isDirectory()){if(o.length>this.qt)return n?.push(`${JSON.stringify(s)} index file is nested too deeply (${o.length} > ${this.qt})`),null;for(const t of this.Gt){const e=y(s,t);if(a=await x(e).catch(()=>null),a?.isFile()){c=e;break}}}if(!a?.isFile())return n?.push(`${JSON.stringify(s)} exists but is not a file`),null;if(this.te){const t=b(c),i=g(c);for(const r of this.te.options(t,e)){if(!r.filename||r.filename.includes(v))continue;const t=await dn({canonicalPath:c,negotiatedPath:y(i,r.filename),...r.info},n);if(t)return t}}return dn({canonicalPath:c,negotiatedPath:c},n)}async debugAllPaths(){return(await this.precompute()).debugAllPaths()}async precompute(){const t=new Map,e=(e,n)=>{const i=t.get(e);(!i||n.p>i.p)&&t.set(e,n)},n=new W({dir:[this.Ht],depth:0});for(const{dir:t,depth:i}of n){const r=await S(y(...t),{withFileTypes:!0,encoding:"utf-8"}),o=new Set(r.map(t=>this.Xt(t.name)));for(const s of r){const r=this.Xt(s.name);if(!this.ee(r))continue;const c=[...t,s.name];if(s.isDirectory())i<this.qt&&n.push({dir:c,depth:i+1}),e(this.Xt(c.slice(1).join("/")),ln);else if(s.isFile()){const n={file:y(...c),dir:y(...t),basename:r,siblings:o},i=this.Gt.indexOf(r);if(-1!==i&&(e(this.Xt(t.slice(1).join("/")),{...n,p:this.Gt.length+1-i}),!this.Wt&&!this.Zt.has(r)))continue;const a=this.Xt(c.slice(1).join("/"));for(let t=0;t<this.Vt.length;++t){const i=this.Vt[t];s.name.endsWith(i)&&e(a.substring(0,a.length-i.length),{...n,p:-t})}}}}return{find:async(e,n={},i)=>{const r=t.get(this.Xt(e.join("/")));if(!r?.file)return i?.push(`${JSON.stringify(e.join("/"))} not found in static file paths`),null;if(this.te)for(const t of this.te.options(r.basename,n)){if(!r.siblings.has(this.Xt(t.filename)))continue;const e=await dn({canonicalPath:r.file,negotiatedPath:y(r.dir,t.filename),...t.info},i);if(e)return e}return dn({canonicalPath:r.file,negotiatedPath:r.file},i)},debugAllPaths:()=>Promise.resolve(new Set([...t].filter(([t,e])=>e.file).map(([t])=>t))),vary:this.vary}}}const ln={file:"",dir:"",basename:"",siblings:new Set,p:1};async function dn(t,e){const n=await k(t.negotiatedPath,a.O_RDONLY).catch(()=>null);if(!n)return e?.push(`failed to open ${JSON.stringify(t.negotiatedPath)}`),null;const i=()=>(n.close().catch(()=>{}),null),r=await n.stat().catch(i);return r?.isFile()?{handle:n,stats:r,...t}:(e?.push(`${JSON.stringify(t.negotiatedPath)} exists but is not a file`),i())}const wn=/*@__PURE__*/Ae(async t=>{const e=Tt(t);if(e.aborted)throw St;e.throwIfAborted();const n=await N(y(A(),"upload"));_t(t,()=>O(n,{recursive:!0}));let i=0;const r=()=>{if(e.aborted)throw St;return y(n,(++i).toString(10).padStart(6,"0"))};return{dir:n,nextFile:r,save:async(t,{mode:n=384}={})=>{const i=r(),o=f(i,{mode:n});try{return await d(t,o,{signal:e}),{path:i,size:o.bytesWritten}}finally{o.close()}}}});function pn(t){const e=at(t);if(!e.I)throw new TypeError("cannot call acceptBody from shouldUpgrade");if(e.C.signal.aborted)throw St;e.ne||e.D||(e.ne=!0,"100-continue"===t.headers.expect?.trim().toLowerCase()&&e.I.j.writeContinue())}function mn(t,{blockRequestHeaders:e=["connection","expect","host","keep-alive","proxy-authorization","transfer-encoding","upgrade","via"],requestHeaders:n=[],blockResponseHeaders:i=["connection","keep-alive","transfer-encoding"],responseHeaders:s=[],agent:c,keepAlive:a=!0,maxSockets:f=10,...u}={}){let h;t.startsWith("https://")?(c??=new P({keepAlive:a,maxSockets:f,...u}),h=o):(c??=new r({keepAlive:a,maxSockets:f,...u}),h=F);const l=t.endsWith("/")?t:t+"/";return qt((r,o)=>new Promise((a,f)=>{const u=Tt(r),w=t=>f(u.aborted?St:new oe(502,{cause:t})),p=new URL(l+r.url?.substring(1)),m=p.toString();if(!m.startsWith(l)&&m!==t)return f(new oe(400,{message:"directory traversal blocked"}));pn(r);let y={...r.headers};yn(y,e);for(const t of n)y=t(r,y);const g=h(p,{agent:c,method:r.method,headers:y,signal:u});g.once("error",w),g.once("response",t=>{if(!o.headersSent){let e={...t.headers};yn(e,i);for(const n of s)e=n(r,t,e);o.writeHead(t.statusCode??200,t.statusMessage,e)}d(t,o).then(a,f)}),d(r,g).catch(w)}))}function yn(t,e){for(const e of Te(t.connection)??[])delete t[e.toLowerCase()];for(const n of e)delete t[n]}function gn({trustedProxyCount:t,trustedProxyAddresses:e,trustedHeaders:n}){const i=e?q(e):()=>!0,r=t??(e?Number.POSITIVE_INFINITY:0),o=new Set(n);return Ae(t=>{const e=e=>{if(o.has(e))return Te(t.headers[e])?.reverse()},n=e("forwarded"),s=e("x-forwarded-for"),c=e("x-forwarded-host"),a=e("x-forwarded-proto"),f=e("x-forwarded-protocol"),u=e("x-url-scheme"),h=e("via")?.map(t=>{const e=/^([^/ ]+\/)?([^ ]+) (.+)$/.exec(t);return e?.[3]?H(e[3]):void 0}),l=[bn(t)];if(n)for(const t of n)try{const e=$e(t);l.push({client:H(e.get("for")),server:H(e.get("by")),host:e.get("host"),proto:e.get("proto")})}catch{l.push({client:void 0,server:void 0,host:void 0,proto:void 0})}else if(s){const t=s.map(H),e=c??[],n=a??f??u??[];let i=l[0].client;for(let r=0;r<t.length;++r){const o=t[r];l.push({client:o,server:h?.[r]??(i?{...i,port:void 0}:void 0),host:e[r],proto:n[r]}),i=o}}else if(h)for(const t of h)l.push({client:void 0,server:t,host:void 0,proto:void 0});let d=Math.min(1+r,l.length);for(let t=0;t<d-1;++t)i(l[t].client)||(d=t+1);return Object.freeze({trusted:l.slice(0,d),untrusted:l.slice(d),outwardChain:l,edge:l[d-1]})})}const bn=t=>({client:{...H(t.socket.remoteAddress)??vn,port:t.socket.remotePort},server:{...H(t.socket.localAddress)??vn,port:t.socket.localPort},host:t.headers.host,proto:void 0}),vn={type:"alias",ip:"_disconnected",port:void 0};function En(t,e){return delete e.forwarded,delete e["x-forwarded-for"],delete e["x-forwarded-host"],delete e["x-forwarded-proto"],delete e["x-forwarded-protocol"],delete e["x-url-scheme"],e}function _n(t,e){const n=En(0,e);return n.forwarded=Sn([bn(t)]),n}const Tn=(t,{onlyTrusted:e=!1}={})=>(n,i)=>{const r=En(0,i),o=t(n);return r.forwarded=Sn([...e?o.trusted:o.outwardChain].reverse()),r};function xn(t,e){let n=t.headers.forwarded;const i=Sn([bn(t)]);n?n+=", "+i:n=i;const r=En(0,e);return r.forwarded=n,r}function Sn(t){return t.filter(t=>t.server||t.client).map(t=>Object.entries({for:t.client?.ip,by:t.server?.ip,host:t.host,proto:t.proto}).filter(([t,e])=>e).map(([t,e])=>e&&/[^a-zA-Z0-9._]/.test(e)?`${t}="${e.replaceAll("\\","\\\\").replaceAll('"','\\"').replaceAll(",","-")}"`:`${t}=${e}`).join("; ")).join(", ")}class $n{constructor(t,{fatal:e=!1}={}){this.ie=t,this.re=e,this.oe=new Uint8Array(4),this.se=new DataView(this.oe.buffer),this.ce=0}decode(t,{stream:e=!1}={}){const n=t.byteLength,i=[];let r=0;if(this.ce>0){if(r=4-this.ce,n<r)return this.oe.set(t,this.ce),this.ce+=n,"";this.oe.set(t.subarray(0,r),this.ce),i.push(this.se.getUint32(0,this.ie)),this.ce=0}const o=new DataView(t.buffer,t.byteOffset,t.byteLength);let s=r;for(const t=n-3;s<t;s+=4)i.push(o.getUint32(s,this.ie));if(e?(s<n&&this.oe.set(t.subarray(s)),this.ce=n-s):(this.ce=0,s<n&&(this.re?ft(new TypeError("The encoded data was not valid for encoding utf-32"),"ERR_ENCODING_INVALID_ENCODED_DATA"):i.push(65533))),i.length>0){try{return String.fromCodePoint(...i)}catch{this.re&&ft(new TypeError("The encoded data was not valid for encoding utf-32"),"ERR_ENCODING_INVALID_ENCODED_DATA")}for(let t=0;t<i.length;++t)i[t]>1114111&&(i[t]=65533);return String.fromCodePoint(...i)}return""}}class kn extends C{constructor(t){super({transform(e,n){try{const i=t.decode(e,{stream:!0});i&&n.enqueue(i)}catch(t){n.error(t)}},flush(e){try{const n=t.decode(X);n&&e.enqueue(n)}catch(t){e.error(t)}}})}}const Nn=new Map;function On(t,e){Nn.set(t.toLowerCase(),e)}function An(){On("utf-32be",{decoder:t=>new $n(!1,t)}),On("utf-32le",{decoder:t=>new $n(!0,t)})}function Rn(t,e={}){const n=Nn.get(t.toLowerCase());if(n)return n.decoder(e);try{return new TextDecoder(t,e)}catch{throw new oe(415,{body:`unsupported charset: ${t}`})}}function Pn(t,e={}){const n=Nn.get(t.toLowerCase());if(n)return n.decoderStream?n.decoderStream(e):new kn(n.decoder(e));try{return new U(t,e)}catch{throw new oe(415,{body:`unsupported charset: ${t}`})}}const Fn=["utf-32be",null,"utf-16be","utf-16be","utf-32le","utf-16le",null,"utf-8"];function Cn(t,e,n){const i=ke(t.headers["if-modified-since"]),r=Te(t.headers["if-none-match"]);if(r){if(Mn(e,n,r))return!1}else if(i&&(n.mtimeMs/1e3|0)<=i)return!1;return!0}function Un(t,e,n){let i=!0;const r=Ee(t);return r.etag&&(i&&=Mn(e,n,r.etag)),r.modifiedSeconds&&(i&&=(n.mtimeMs/1e3|0)===r.modifiedSeconds),i}function Mn(t,e,n){if(n.includes("*"))return!0;const i=t.getHeader("etag");if("string"==typeof i){if(n.includes(i))return!0;if(i.startsWith('W/"'))return!1}return!!n.some(t=>t.startsWith('W/"'))&&n.includes(He(t.getHeader("content-encoding"),e))}class Bn extends C{constructor(t,e){super({transform(i,r){n+=i.byteLength,n>t?r.error(e):r.enqueue(i)}});let n=0}}function Dn(t,{maxContentBytes:e=Number.POSITIVE_INFINITY,maxNetworkBytes:n=e,maxEncodingSteps:i=1}={}){const r=xe(t.headers["content-length"]);if(void 0!==r&&r>n)throw new oe(413);const o=Te(t.headers["content-encoding"])??[];if(o.length>i)throw new oe(415,{body:"too many content-encoding stages"});pn(t);let s=D.toWeb(t);void 0===r&&Number.isFinite(n)&&(s=s.pipeThrough(new Bn(n,new oe(413))));for(const t of o.reverse())s=s.pipeThrough(qn(t));return Number.isFinite(e)&&(s=s.pipeThrough(new Bn(e,new oe(413,{body:"decoded content too large"})))),s}function In(t,e={}){const n=Dn(t,e),i=ve(t)??e.defaultCharset??"utf-8";return n.pipeThrough(Pn(i,e))}async function jn(t,e={}){const n=[];for await(const i of In(t,e))n.push(i);return n.join("")}async function Hn(t,e={}){const n=await(async(t,e)=>{const n=t.getReader(),i=new Uint8Array(3);let r=0,o=null;for(;;){const t=await n.read(),e=3-r;if(t.done){0===r?(i[0]=1,i[1]=1):1===r&&(i[1]=i[0]),i[2]=i[0],o=null;break}if(o=t.value,o.byteLength>=e){i.set(o.subarray(0,e),r);break}i.set(o,r),r+=o.byteLength}const s=Fn[(i[0]?4:0)|(i[1]?2:0)|(i[2]?1:0)];if(!s)throw n.cancel(),new oe(415,{body:"invalid JSON encoding"});const c=Pn(s,e),a=c.writable.getWriter();return r&&a.write(i.subarray(0,r)),o&&a.write(o),n.releaseLock(),a.releaseLock(),t.pipeThrough(c)})(Dn(t,e),e),i=[];for await(const t of n)i.push(t);return JSON.parse(i.join(""))}function qn(t){switch(t.toLowerCase()){case"gzip":case"x-gzip":return new M("gzip");case"deflate":return new M("deflate");case"br":try{return new M("brotli")}catch{return I.toWeb(w.createBrotliDecompress())}case"zstd":try{return I.toWeb(w.createZstdDecompress())}catch{throw new oe(415,{body:"unsupported content encoding"})}default:throw new oe(415,{body:"unknown content encoding"})}}function Jn(t){if(!t)return null;const[e,n]=ge(t,";"),i=new Map;if(n){const t=/\s*([!#-'*+\-.0-:>-Z^-z|~]+)=(?:([!#-'*+\-.0-:>-Z^-z|~]+)|"((?:[^\x00-\x08\x0a-\x1f"\\\x7f]|\\.)*)")\s*(;|$)/gy;for(;t.lastIndex!==n.length;){const e=t.exec(n);if(!e)return null;const r=e[1].toLowerCase(),o=e[2]??e[3]?.replaceAll(/\\(.)/g,"$1")??"";i.has(r)||i.set(r,o)}}return{mime:e.trim().toLowerCase(),params:i}}function Ln(t,e,n,i){const r=t.byteLength;for(;e<r;){for(;e<r;++e){const n=t[e];if(32!==n&&9!==n)break}if(e===r)break;if(59!==t[e++])return!1;for(;e<r;++e){const n=t[e];if(32!==n&&9!==n)break}if(e===r)return!1;const o=e;for(;e<r;++e){const n=t[e];if(!Wn[n]){if(61===n)break;return!1}}if(e===r)return!1;const s=t.latin1Slice(o,e).toLowerCase();if("*"===s[s.length-1]){const i=++e;for(;e<r;++e){const n=t[e];if(!Vn[n]){if(39!==n)return!1;break}}if(e===r)return!1;const o=Rn(t.latin1Slice(i,e));for(++e;e<r&&39!==t[e];++e);if(e===r)return!1;if(++e===r)return!1;let c=e;const a=[];for(;e<r;++e){const n=t[e];if(1!==Gn[n]){if(37===n){let n,i;if(e+2<r&&16!==(n=Xn[t[e+1]])&&16!==(i=Xn[t[e+2]])){const r=(n<<4)+i;e>c&&a.push(o.decode(t.subarray(c,e),{stream:!0})),a.push(o.decode(Buffer.from([r]),{stream:!0})),c=(e+=2)+1;continue}return!1}break}}a.push(o.decode(t.subarray(c,e)));const f=a.join("");n.has(s)||n.set(s,f);continue}if(++e===r)return!1;if(34===t[e]){let o=++e,c=!1;const a=[];for(;e<r;++e){const n=t[e];if(92!==n){if(34===n){if(c){o=e,c=!1;continue}a.push(i.decode(t.subarray(o,e)));break}if(c&&(o=e-1,c=!1),!Zn[n])return!1}else c?(o=e,c=!1):(a.push(i.decode(t.subarray(o,e),{stream:!0})),c=!0)}if(e===r)return!1;++e,n.has(s)||n.set(s,a.join(""));continue}let c=e;for(;e<r;++e){const n=t[e];if(!Wn[n]){if(e===c)return!1;break}}n.has(s)||n.set(s,i.decode(t.subarray(c,e)))}return!0}const zn=[1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],Wn=/*@__PURE__*/(()=>{const t=new Uint8Array(256);return t.set([1,0,1,1,1,1,1,0,0,1,1,0,1,1,0,...zn,0,1,0,1],33),t})(),Gn=/*@__PURE__*/(()=>{const t=new Uint8Array(256);return t.set([1,0,1,1,0,1,0,0,0,0,1,0,1,1,0,...zn,0,1,0,1],33),t})(),Vn=/*@__PURE__*/(()=>{const t=new Uint8Array(256);return t.set([1,0,1,1,1,1,0,0,0,0,1,0,1,0,0,...zn,1,0,1,1],33),t})(),Zn=/*@__PURE__*/(()=>{const t=new Uint8Array(256);return t.fill(1,32,256),t[9]=1,t[34]=0,t[92]=0,t[127]=0,t})(),Xn=/*@__PURE__*/(()=>{const t=new Uint8Array(256).fill(16);for(let e=0;e<10;++e)t[48+e]=e;for(let e=0;e<6;++e)t[65+e]=e+10,t[97+e]=e+10;return t})();class Yn{constructor(t,e){const n=t.byteLength;if(!n||n>65535)throw new RangeError("invalid needle");this.ae=t,this.fe=e,this.ue=null,this.he=0,this.le=null}push(t){let e=0;const n=t.byteLength,i=this.ae,r=i.byteLength-1,o=n-r;let s=-this.he;if(this.he){const c=this.le,a=this.ue,f=i[r];if(o>0){const n=t[s+r];n!==f||t.compare(i,-s,r,0,s+r)?s+=c[n]:(this.fe(!0,X,0,0,!0),this.he=0,e=s+=r+1)}const u=o<0?o:0;for(;s<u;){const n=t[s+r];if(n===f&&!a.compare(i,0,-s,this.he+s,this.he)&&!t.compare(i,-s,r,0,s+r)){this.fe(!0,a,0,this.he+s,!1),this.he=0,e=s+=r+1;break}s+=c[n]}const h=this.he;if(h>0){const e=i[0];for(;s<0;){const r=a.subarray(0,h).indexOf(e,h+s);if(-1===r){s=0;break}const o=h-r;if(!a.compare(i,1,o,r+1,h)&&!t.compare(i,o,o+n))return r&&(this.fe(!1,a,0,r,!1),a.copy(a,0,r,o)),a.set(t,o),void(this.he+=n-r);s=r+1-h}this.fe(!1,a,0,h,!1),this.he=0}}for(;s<o;){const n=t.indexOf(i,s);if(-1!==n){if(this.fe(!0,t,e,n,!0),n===o+1)return;e=s=n+r+1}else s=o}const c=i[0];for(;s<n;){const o=t.indexOf(c,s);if(-1===o)return void this.fe(!1,t,e,n,!0);if(!t.compare(i,1,n-o,o+1)){if(!this.ue){this.ue=Buffer.allocUnsafe(r),this.le=new Uint16Array(256).fill(r+1);for(let t=0;t<r;++t)this.le[i[t]]=r-t}return t.copy(this.ue,0,o),this.he=n-o,void(o>e&&this.fe(!1,t,e,o,!0))}s=o+1}n>e&&this.fe(!1,t,e,n,!0)}destroy(){const t=this.he;t&&this.ue&&this.fe(!1,this.ue,0,t,!1),this.he=0}}class Kn extends j{constructor({limits:t={},preservePath:e,highWaterMark:n,fileHwm:i,defParamCharset:r="utf-8",defCharset:o="utf-8"},s){super({autoDestroy:!0,emitClose:!0,highWaterMark:n,write:Qn,destroy:ti,final:ei});const c=s.get("boundary");if(!c)throw new oe(400,{body:"multipart boundary not found"});if(c.length>70)throw new oe(400,{body:"multipart boundary too long"});const a=Rn(r),f={autoDestroy:!0,emitClose:!0,highWaterMark:i},u=t.fieldSize??1048576,h=t.fileSize??Number.POSITIVE_INFINITY,l=t.fieldNameSize??100,d=t.files??Number.POSITIVE_INFINITY,w=t.fields??Number.POSITIVE_INFINITY,p=t.parts??Number.POSITIVE_INFINITY;let m,y,g,b,v,E=0,_=0,T=0,x=-1;this.de=0,this.we=!1;let S=!1;const $=new ni(t=>{this.pe=void 0;const n=t["content-disposition"];if(!n)return void(x=-1);const i=((t,e)=>{if(!t.byteLength)return null;const n=new Map;let i=0;for(;i<t.byteLength;++i)if(!Wn[t[i]]){if(!Ln(t,i,n,e))return null;break}return{type:t.latin1Slice(0,i).toLowerCase(),params:n}})(Buffer.from(n,"latin1"),a);if("form-data"!==i?.type)return void(x=-1);v=i.params.get("name")??"",S=v.length>l,S&&(v=v.substring(0,l));let r=i.params.get("filename*")??i.params.get("filename");void 0===r||e||(r=(t=>{for(let e=t.length;e-- >0;)if("/"===t[e]||"\\"===t[e]){t=t.slice(e+1);break}return".."===t||"."===t?"":t})(r));const s=Jn(t["content-type"]);b=s?.mime??"text/plain";const c=s?.params.get("charset")?.toLowerCase()??o;if(y=Rn(c),g=t["content-transfer-encoding"]?.toLowerCase()??"7bit","application/octet-stream"===b||void 0!==r){if(T++===d&&this.emit("filesLimit"),T>d||0===this.listenerCount("file"))return void(x=-1);this.me=new ii(f,this),++this.de,this.emit("file",v,this.me,{nameTruncated:S,filename:r,encoding:g,mimeType:b}),x=h}else{if(_++===w&&this.emit("fieldsLimit"),_>w||0===this.listenerCount("field"))return void(x=-1);m="",x=u}});let k=0;const N=Buffer.from(`\r\n--${c}`,"latin1");this.ye=new Yn(N,(t,e,n,i,r)=>{try{if(n===i)return;if(k){if(1===k){if(13===e[n])k=2;else{if(45!==e[n])return void(k=0);k=3}if(++n===i)return}if(2!==k){if(k=0,45!==e[n])return;return this.we=!0,void(this.ye=oi)}if(k=0,10!==e[n++])return;if(E++===p&&this.emit("partsLimit"),E>p)return;if(this.pe=$,n===i)return}if(this.pe){const t=this.pe.push(e,n,i);if(-1===t)return this.pe=void 0,$.reset(),void this.emit("error",new oe(400,{body:"malformed part header"}));if(t===i)return;n=t}if(x>=0){const t=Math.min(i,n+x);if(x-=i-n,this.me){if(t>n){let i;r?i=e.subarray(n,t):(i=Buffer.allocUnsafe(t-n),e.copy(i,0,n,t)),this.me.push(i)||(this.me.ge??=this.be,this.be=void 0)}x<0&&(this.me.emit("limit"),this.me.truncated=!0)}else void 0!==m&&(m+=e.latin1Slice(n,t))}}finally{t&&(this.pe?(this.emit("error",new oe(400,{body:"unexpected end of headers"})),this.pe=void 0):this.me?(this.me.push(null),this.me=void 0):void 0!==m&&(this.emit("field",v,y.decode(Buffer.from(m,"latin1")),{nameTruncated:S,valueTruncated:x<0,encoding:g,mimeType:b}),m=void 0),k=1,x=-1)}}),this.write(si)}ve(){if(this.pe)return new oe(400,{body:"malformed part header"});const t=this.me;return t&&(this.me=void 0,t.destroy(new oe(400,{body:"unexpected end of file"}))),this.we?null:new oe(400,{body:"unexpected end of form"})}}function Qn(t,e,n){this.be=n,this.ye.push(t);const i=this.be;i&&(this.be=void 0,i())}function ti(t,e){this.pe=void 0,this.ye=oi,t??=this.ve();const n=this.me;n&&(this.me=void 0,n.destroy(t??void 0)),e(t)}function ei(t){if(this.ye.destroy(),!this.we)return t(new oe(400,{body:"unexpected end of form"}));this.de?this.Ee=()=>t(this.ve()):t(this.ve())}class ni{constructor(t){this._e=Object.create(null),this.Te=0,this.xe=0,this.m=0,this.ht="",this.Se="",this.$e=0,this.fe=t}reset(){this._e=Object.create(null),this.Te=0,this.xe=0,this.m=0,this.ht="",this.Se="",this.$e=0}push(t,e,n){let i=e,r=e;const o=Math.min(n,e+16384-this.xe);for(;r<o;)switch(this.m){case 0:for(;r<o&&Wn[t[r]];++r);if(r>i&&(this.ht+=t.latin1Slice(i,r)),r<o){if(58!==t[r])return-1;if(!this.ht)return-1;++r,this.m=1}break;case 1:for(;r<o;++r){const e=t[r];if(32!==e&&9!==e){i=r,this.m=2;break}}break;case 2:switch(this.$e){case 0:for(;r<o;++r){const e=t[r];if(e<32||127===e){if(13!==e)return-1;++this.$e;break}}this.Se+=t.latin1Slice(i,r),++r;break;case 1:if(10!==t[r++])return-1;++this.$e;break;case 2:{const e=t[r];32===e||9===e?(i=r,this.$e=0):(++this.Te<2e3&&(this._e[this.ht.toLowerCase()]??=this.Se),13===e?(++this.$e,++r):(i=r,this.$e=0,this.m=0,this.ht="",this.Se=""));break}case 3:{if(10!==t[r++])return-1;const e=this._e;return this.reset(),this.fe(e),r}}}return o<n?-1:(this.xe+=o-e,o)}}class ii extends D{constructor(t,e){super({...t,read:ri}),this.truncated=!1,this.once("end",()=>{if(ri.call(this),0===--e.de&&e.Ee){const t=e.Ee;e.Ee=void 0,process.nextTick(t)}})}}function ri(t){const e=this.ge;e&&(this.ge=void 0,e())}const oi={push:()=>{},destroy:()=>{}},si=/*@__PURE__*/Buffer.from("\r\n");class ci extends j{constructor({limits:t={},highWaterMark:e,defCharset:n="utf-8"},i){super({autoDestroy:!0,emitClose:!0,highWaterMark:e,write:ai,final:fi}),this.ke=i.get("charset")??n,this.Ne=t.fieldSize??1048576,this.Oe=t.fields??Number.POSITIVE_INFINITY,this.Ae=t.fieldNameSize??100,this.Re=0,this.Pe=!0,this.Fe="",this.Ce=this.Ae,this.Ue=0,this.Me="",this.Be=!1,this.De=-2,this.Ie=/^utf-?8$/i.test(this.ke)?1:/^(latin-?1|iso[\-_]?8859-?1|(us-)?ascii)$/i.test(this.ke)?2:0,this.je=Rn(this.ke)}}function ai(t,e,n){if(!t.byteLength)return n();if(this.Re>=this.Oe)return this.Re||t===pi||(++this.Re,this.emit("fieldsLimit")),n();const i=t.byteLength;let r=0,o=this.De;if(-2!==o){if(-1===o){if(16===(o=Xn[t[r++]]))return n(new oe(400,{body:"malformed urlencoded form"}));if(this.Ue|=o,r===i)return this.De=o,n()}const e=Xn[t[r++]];if(16===e)return n(new oe(400,{body:"malformed urlencoded form"}));if(this.Fe+=String.fromCharCode((o<<4)+e),this.De=-2,r===i)return n()}for(wi[ui]=1,wi[hi]=1,wi[li]=1,wi[di]=this.Pe?1:0;;){const e=r;for(;r<i&&!wi[t[r]];++r);if(r>e&&this.Ce>=0&&((this.Ce-=r-e)<0?this.Fe+=t.latin1Slice(e,r+this.Ce):this.Fe+=t.latin1Slice(e,r)),r===i)return n();switch(t[r++]){case ui:for(;;){if(--this.Ce<0){wi[ui]=0,wi[li]=0;break}if(r===i)return this.De=-1,n();const e=Xn[t[r++]];if(16===e)return n(new oe(400,{body:"malformed urlencoded form"}));if(this.Ue|=e,r===i)return this.De=e,n();const o=Xn[t[r++]];if(16===o)return n(new oe(400,{body:"malformed urlencoded form"}));if(this.Fe+=String.fromCharCode((e<<4)+o),r===i)return n();if(t[r]!==ui)break;r++}break;case hi:const e=!this.Ie||1===this.Ie&&8&this.Ue?this.je.decode(Buffer.from(this.Fe,"latin1")):this.Fe;if(this.Pe?(e||this.Ce<0)&&this.emit("field",this.Fe,"",{nameTruncated:this.Ce<0,valueTruncated:!1,encoding:this.ke,mimeType:"text/plain"}):(this.emit("field",this.Me,e,{nameTruncated:this.Be,valueTruncated:this.Ce<0,encoding:this.ke,mimeType:"text/plain"}),this.Me="",this.Be=!1,this.Pe=!0,wi[di]=1),wi[ui]=1,wi[li]=1,this.Fe="",this.Ce=this.Ae,this.Ue=0,++this.Re===this.Oe&&t!==pi)return this.emit("fieldsLimit"),n();break;case li:--this.Ce<0?(wi[ui]=0,wi[li]=0):this.Fe+=" ";break;case di:this.Me=!this.Ie||1===this.Ie&&8&this.Ue?this.je.decode(Buffer.from(this.Fe,"latin1")):this.Fe,this.Be=this.Ce<0,this.Pe=!1,wi[di]=0,wi[ui]=1,wi[li]=1,this.Fe="",this.Ue=0,this.Ce=this.Ne}if(r===i)return n()}}function fi(t){ai.call(this,pi,void 0,t)}const ui=37,hi=38,li=43,di=61,wi=/*@__PURE__*/new Uint8Array(256),pi=/*@__PURE__*/Buffer.from([hi]);function mi(t,{closeAfterErrorDelay:e=500,...n}={}){const i=((t,e={})=>{const n=t["content-type"];if(!n)throw new oe(400,{body:"missing content-type"});const i=Jn(n);if(!i)throw new oe(400,{body:"malformed content-type"});const r="application/x-www-form-urlencoded"===i.mime?ci:"multipart/form-data"!==i.mime||e.blockMultipart?null:Kn;if(!r)throw new oe(415);return new r(e,i.params)})(t.headers,n);pn(t);const r=new G,o=(n,o)=>{if(r.fail(new oe(n,o)),i.removeAllListeners(),t.unpipe(i),t.resume(),e>=0){const n=setTimeout(()=>t.socket.destroy(),e);t.once("end",()=>clearTimeout(n))}};i.on("field",(t,e,{nameTruncated:n,valueTruncated:i,encoding:s,mimeType:c})=>t?n?o(400,{body:`field name ${JSON.stringify(t)}... too long`}):i?o(400,{body:`value for ${JSON.stringify(t)} too long`}):void r.push({name:t,encoding:s,mimeType:c,type:"string",value:e}):o(400,{body:"missing field name"})),i.on("file",(t,e,{nameTruncated:n,filename:i,encoding:s,mimeType:c})=>t?n?o(400,{body:`field name ${JSON.stringify(t)}... too long`}):void(i?(e.once("limit",()=>o(400,{body:`uploaded file for ${JSON.stringify(t)}: ${JSON.stringify(i)} too large`})),r.push({name:t,encoding:s,mimeType:c,type:"file",value:e,filename:i})):e.resume()):o(400,{body:"missing field name"})),t.once("error",e=>{t.readableAborted?r.fail(St):o(500,{body:"request error",headers:{connection:"close"},cause:e})}),i.once("error",t=>o(400,{body:"error parsing form data",cause:t})),i.once("partsLimit",()=>o(400,{body:"too many parts"})),i.once("filesLimit",()=>o(400,{body:"too many files"})),i.once("fieldsLimit",()=>o(400,{body:"too many fields"}));const s=()=>r.close("complete");return i.once("close",s),_t(t,s),t.pipe(i),r}async function yi(t,e={}){const n=new FormData,i=new Map;for await(const r of mi(t,e))if("file"===r.type){const o=r.value;let s=await(e.preCheckFile?.({fieldName:r.name,filename:r.filename,encoding:r.encoding,mimeType:r.mimeType,maxBytes:e.limits?.fileSize}));const c=t=>{if("function"==typeof s){const e=s;return s=void 0,e({actualBytes:t})}};_t(t,()=>c(0));const a=await wn(t),f=await a.save(o,{mode:384});await c(f.size);const h=new File([await u(f.path)],r.filename,{type:r.mimeType});i.set(h,f.path),n.append(r.name,h)}else{let t=r.value;e.trimAllValues&&(t=t.trim()),n.append(r.name,t)}return Object.assign(n,{getTempFilePath(t){const e=i.get(t);if(!e)throw new RangeError("unknown file");return e},getBoolean(t){const e=n.get(t);return null===e?null:"true"===e||"on"===e},getString(t){const e=n.get(t);return"string"==typeof e?e:null},getAllStrings:t=>n.getAll(t).filter(t=>"string"==typeof t),getFile(t){const e=n.get(t);return"string"==typeof e?null:e},getAllFiles:t=>n.getAll(t).filter(t=>"string"!=typeof t)})}const gi="win32"===/*@__PURE__*/R();function bi(t,{rejectPotentiallyUnsafe:e=!0}={}){let n=[];const i=st(t);if(i){if("/"===i.F)return[];n=i.F.split("/")}else{const e=Y(t).pathname;if("/"===e)return[];n=e.split("/").map(decodeURIComponent)}if(""!==n[0])throw new oe(400,{body:"invalid path"});if(n.shift(),e){const t=gi?Ei:vi;if(n.some(e=>t.test(e)||e.includes(v)))throw new oe(400,{body:"invalid path"});if(n.slice(0,n.length-1).includes(""))throw new oe(400,{body:"invalid path"})}return n}const vi=/[\x00-\x1F\x7F/]|^(\.\.?|~)$/,Ei=/[\x00-\x1F"*/:<>?\\|\x7F]|^[\s.]*$|^(CON|PRN|AUX|NUL|(COM|LPT)[\d\xB9\xB2\xB3])(\.|$)/i,_i=t=>new Promise(e=>{const n=()=>{t.cork(),e()};t instanceof s?t.write(X,n):t.once("drain",n),t.uncork()});async function Ti(t,e,{delimiter:n=",",newline:i="\n",quote:r='"',encoding:o="utf-8",headerRow:c,end:a=!0}={}){"string"==typeof n&&(n=Buffer.from(n,o)),"string"==typeof i&&(i=Buffer.from(i,o));const f="string"==typeof r?Buffer.from(r,o):r,u=r+r,h=e=>{if(!e)return!0;const n=e.includes(r);return!n&&xi.test(e)?t.write(e,o):(t.write(f),n?t.write(e.replaceAll(r,u),o):t.write(e,o),t.write(f))};t instanceof s&&!t.headersSent&&!t.hasHeader("content-type")&&t.setHeader("content-type","text/csv; charset="+o+(c?"; header=present":!1===c?"; header=absent":"")),t.cork();try{t.write(X);for await(const r of e){if(t.writableAborted)break;let e=0;if(Symbol.iterator in r)for(const i of r)e&&t.write(n),h(i)||await _i(t),++e;else for await(const i of r)e&&t.write(n),h(i)||await _i(t),++e;t.write(i)||await _i(t)}}finally{t.uncork()}a&&t.end()}const xi=/^[^"':;,\\\r\n\t ]*$/i;function Si(t){if(!t||"object"!=typeof t)return!1;const e=t;return"number"==typeof e.fd&&"function"==typeof e.stat&&"function"==typeof e.createReadStream}class $i{constructor(t){(t=>"He"in t&&"function"==typeof t.pipe)(t)&&(t=D.toWeb(t)),this.lt=t.getReader(),this.qe=null,this.Je=0,this.m=0}getRange(t,e){if(e<t)throw new RangeError("invalid range");if(t<this.Je)throw new RangeError("non-sequential range");if(this.m)throw new TypeError("previous range still active");let n=e-t+1,i=t-this.Je;this.Je=e+1,this.m=1;const r=this,o=(t,e)=>{const r=t.byteLength;r<=i?i-=r:r>i+n?(this.qe=t.subarray(i+n),e.enqueue(t.subarray(i,i+n)),n=0):i>0?(e.enqueue(t.subarray(i)),n-=r-i,i=0):(e.enqueue(t),n-=r)};return new B({start(t){if(r.qe){const e=r.qe;r.qe=null,o(e,t)}},async pull(t){if(n<=0)return r.m=0,void t.close();const e=await r.lt.read();e.done?t.error(new RangeError("range exceeds content")):"string"==typeof e.value?o(Buffer.from(e.value,"utf-8"),t):e.value instanceof Uint8Array?o(e.value,t):t.error(new TypeError("invalid stream type: must contain bytes or UTF-8 text"))}})}async close(){await this.lt.cancel(),this.lt.releaseLock()}}function ki(t,{forceSequential:e=!1,mergeOverlapDistance:n=100}={}){const i=[];if(n>=0)for(const e of t.ranges){let t=null,r=0;for(let o=0;o<i.length;++o){const s=i[o];e.end>=s.start-n-1&&s.end>=e.start-n-1?t?(++r,t.start=Math.min(t.start,s.start),t.end=Math.max(t.end,s.end)):(t=s,t.start=Math.min(t.start,e.start),t.end=Math.max(t.end,e.end)):r>0&&(i[o-r]=s)}t?i.length-=r:i.push({...e})}else i.push(...t.ranges);if(e)for(let t=0;t<i.length-1;++t)if(i[t].start>i[t+1].start){i.sort((t,e)=>t.start-e.start);break}return{ranges:i,totalSize:t.totalSize}}async function Ni(t,e,n,i){if("string"==typeof n||Si(n)||(i=ki(i,{mergeOverlapDistance:0,forceSequential:!0})),1===i.ranges.length){const r=i.ranges[0];if(e.setHeader("content-length",r.end-r.start+1),e.setHeader("content-range",`bytes ${r.start}-${r.end}/${i.totalSize??"*"}`),e.writeHead(206),"HEAD"===t.method)return void e.end();const o=await Oi(n);return await d(o.Le(r.start,r.end),e),void(o.ze&&await o.ze())}const r=e.getHeader("content-type"),o=l()+l()+"ABCDEFGHIJKLMNOPQRSTUVWXYZ";e.setHeader("content-type",`multipart/byteranges; boundary=${o}`);const s=i.ranges.map(t=>({o:[`--${o}`,...ht({"content-type":r,"content-range":`bytes ${t.start}-${t.end}/${i.totalSize??"*"}`}),"",""].join("\r\n"),We:t})),c=`--${o}--`;let a=c.length;for(const{o:t,We:e}of s)a+=t.length+e.end-e.start+1+2;if(e.setHeader("content-length",a),"HEAD"===t.method)return void e.end();let f="";const u=await Oi(n);try{for(const{o:t,We:n}of s)e.write(f+t,"ascii"),await d(u.Le(n.start,n.end),e,{end:!1}),f="\r\n";e.end(f+c)}finally{u.ze&&await u.ze()}}async function Oi(t){if("string"==typeof t){const e=await k(t,"r");return{Le:(t,n)=>e.createReadStream({start:t,end:n,autoClose:!1}),ze:()=>e.close()}}if(Si(t))return{Le:(e,n)=>t.createReadStream({start:e,end:n,autoClose:!1})};{const e=new $i(t);return{Le:(t,n)=>e.getRange(t,n),ze:()=>e.close()}}}async function Ai(t,e,n,i,r){if(i||("string"==typeof n?i=await x(n):Si(n)&&(i=await n.stat())),i){if("GET"===t.method||"HEAD"===t.method){if(!Cn(t,e,i))return void e.writeHead(304).end();e.setHeader("accept-ranges","bytes");const o=_e(t,i.size,r);if(o&&Un(t,e,i))return Ni(t,e,n,ki(o,r))}e.setHeader("content-length",i.size)}if(e.writeHead(e.statusCode,e.statusMessage),"HEAD"!==t.method)return"string"==typeof n?n=c(n):Si(n)&&(n=n.createReadStream({start:0,autoClose:!1})),d(n,e);e.end()}function Ri(t,e,{replacer:n,space:i,undefinedAsNull:r=!1,encoding:o="utf-8",end:c=!0}={}){const a=JSON.stringify(e,n,i)??(r?"null":void 0);t instanceof s&&!t.headersSent&&(t.hasHeader("content-type")||t.setHeader("content-type","application/json"),c&&t.setHeader("content-length",Buffer.byteLength(a,o))),c?t.end(a,o):a&&t.write(a,o)}async function Pi(t,e,{replacer:n=null,space:i="",undefinedAsNull:r=!1,encoding:o="utf-8",end:c=!0}={}){if(Array.isArray(n)){const t=new Set(n.map(t=>String(t)));n=function(e,n){return null===this||Array.isArray(this)||t.has(e)?n:void 0}}"number"==typeof i&&(i=" ".substring(0,i));const a={Ge:e=>t.write(e,o),Ve:()=>_i(t),Ze:n,Xe:i};if(t instanceof s&&!t.headersSent&&!t.hasHeader("content-type")&&t.setHeader("content-type","application/json"),e=Ci(null,"",e,a),Ui(e))r&&a.Ge("null");else{t.cork(),t.write(X);try{await Fi(a,e,i?"\n":"")}finally{t.uncork()}}c&&t.end()}async function Fi(t,e,n){const i=(i,r,o)=>{t.Ge(i);const s=n+t.Xe,c=t.Xe?": ":":";let a=!0;return{i:async(n,i)=>{const r=Ci(e,n,i,t);o&&Ui(r)||(a?a=!1:t.Ge(","),t.Ge(s),o&&(t.Ge(JSON.stringify(n))||await t.Ve(),t.Ge(c)),await Fi(t,r,s))},ze:()=>{a||t.Ge(n),t.Ge(r)}}};if(null===e||"object"!=typeof e||e instanceof String||e instanceof Number||e instanceof Boolean||e instanceof Function||e instanceof Symbol||e instanceof BigInt||Mi(e))t.Ge(JSON.stringify(e)??"null")||await t.Ve();else if(e instanceof D){t.Ge('"');for await(const n of e){if("string"!=typeof n)throw new TypeError("Readables must have an encoding");const e=JSON.stringify(n);t.Ge(e.substring(1,e.length-1))||await t.Ve()}t.Ge('"')}else if(e instanceof Map){const t=i("{","}",!0);for(const[n,i]of e)await t.i(n,i);t.ze()}else if(Bi(e)){let t=0;const n=i("[","]",!1);for(const i of e)await n.i(String(t++),i);n.ze()}else if(Di(e)){let t=0;const n=i("[","]",!1);for await(const i of e)await n.i(String(t++),i);n.ze()}else{const t=i("{","}",!0);for(const[n,i]of Object.entries(e))await t.i(n,i);t.ze()}}function Ci(t,e,n,i){return i.Ze&&(n=i.Ze.call(t,e,n)),n&&"object"==typeof n&&"function"==typeof n.toJSON&&(n=n.toJSON(e)),n}const Ui=t=>void 0===t||"function"==typeof t||"symbol"==typeof t||t instanceof Function||t instanceof Symbol,Mi=t=>JSON.isRawJSON?.(t)??!1,Bi=t=>Symbol.iterator in t,Di=t=>Symbol.asyncIterator in t;class Ii{constructor(t,e,{keepaliveInterval:n=15e3,softCloseReconnectDelay:i=500,softCloseReconnectStagger:r=2e3}={}){this.Ye=e,this.Ke=n??0,this.C=new AbortController,e.setHeader("content-type","text/event-stream"),e.setHeader("x-accel-buffering","no"),e.setHeader("cache-control","no-store"),e.writeHead(200),e.flushHeaders(),this.ping=this.ping.bind(this),this.Qe(),t.once("close",()=>this.close()),wt(t,()=>this.close(i,r))}get signal(){return this.C.signal}get open(){return!this.C.signal.aborted}Qe(){this.Ke&&(this.tn=setTimeout(this.ping,this.Ke))}ping(){!this.C.signal.aborted&&this.Ye.writable&&(clearTimeout(this.tn),this.Ye.write(":\n\n",()=>this.Qe()))}send({event:t,id:e,data:n,reconnectDelay:i=-1}){return this.sendFields([["event",t],["id",e],["data",n],["retry",i>=0?String(0|i):void 0]])}async sendFields(t){let e;this.C.signal.throwIfAborted(),this.Ye.cork();try{let n=!1;for(const[e,i]of t){if(void 0===i)continue;const t=i.split(/(?<=\n)|(?<=\r)(?!\n)/g);for(let n of t)this.Ye.write(e)," "===n[0]?this.Ye.write(": "):this.Ye.write(":"),this.Ye.write(n);/[\r\n]$/.test(i)?(this.Ye.write(e),this.Ye.write(":\n")):this.Ye.write("\n"),n=!0}if(!n)return;clearTimeout(this.tn),this.Ye.write("\n",()=>e())}finally{this.Ye.uncork()}await new Promise(t=>{e=t}),this.Qe()}async close(t=0,e=0){if(this.C.signal.aborted){if(this.Ye.closed)return;return new Promise(t=>this.Ye.once("close",t))}this.Ke=0,clearTimeout(this.tn),this.C.abort(new Error("ServerSentEvents closed")),await new Promise(n=>{if(this.Ye.writable&&(t>0||e>0)){const i=t+Math.random()*e;this.Ye.end(`retry:${0|i}\n\n`,n)}else this.Ye.end(n)})}}const ji=async(t,{mode:e="dynamic",fallback:n,verbose:i,callback:r=Hi,...o}={})=>{const s=await hn.build(E(process.cwd(),t),o);let c=null;const a=n?.statusCode??200;if(n){let t=n.filePath;t.startsWith("/")&&(t=t.substring(1)),c=t.split("/")}const f="dynamic"===e?{}:{rejectPotentiallyUnsafe:!1},u="dynamic"===e?s:await s.precompute();return{handleRequest:async(t,e)=>{if("GET"!==t.method&&"HEAD"!==t.method)return $t;let n=!1;const o=bi(t,f),s={mime:Se(t.headers.accept),language:Se(t.headers["accept-language"]),encoding:Se(t.headers["accept-encoding"])},h=[];let l=await u.find(o,s,i?h:void 0);if(!l){if(!c)return i&&an(t,new Error(h.join(", ")),"serving static content"),$t;if(n=!0,l=await u.find(c,s,h),!l)throw new oe(500,{message:`failed to find fallback file: ${h.join(", ")}`})}try{n&&(e.statusCode=a),e.setHeader("content-type",l.mime??nn(m(l.canonicalPath))),l.encoding&&"identity"!==l.encoding&&e.setHeader("content-encoding",l.encoding);const i=u.vary;if(i){const t=e.getHeader("vary")??"";e.setHeader("vary",(t?t+", ":"")+i)}await r(t,e,l,n),await Ai(t,e,l.handle,l.stats)}finally{l.handle.close().catch(()=>{})}}}};function Hi(t,e,n){e.setHeader("etag",He(e.getHeader("content-encoding"),n.stats)),e.setHeader("last-modified",n.stats.mtime.toUTCString())}class qi extends Error{constructor(t,{message:e,statusMessage:n,...i}={}){super(e,i),this.statusCode=0|t,this.statusMessage=n??"",this.name=`WebSocketError(${this.statusCode} ${this.statusMessage})`}static NORMAL_CLOSURE=1e3;static GOING_AWAY=1001;static UNSUPPORTED_DATA=1003;static POLICY_VIOLATION=1008;static MESSAGE_TOO_BIG=1009;static INTERNAL_SERVER_ERROR=1011;static SERVICE_RESTART=1012;static TRY_AGAIN_LATER=1013;static BAD_GATEWAY=1014}function Ji(t,{softCloseStatusCode:e=qi.GOING_AWAY,...n}={}){const i=(i,r,o)=>new Promise((s,c)=>{const a=new t({...n,noServer:!0,clientTracking:!1});a.once("wsClientError",c),a.handleUpgrade(i,r,o,t=>{a.off("wsClientError",c),o=X,s({return:t,onError:e=>{const n=V(e,qi);if(n)return void t.close(n.statusCode,n.statusMessage);const i=V(e,oe)??new oe(500),r=i.statusCode>=500?qi.INTERNAL_SERVER_ERROR:4e3+i.statusCode;t.close(r,i.statusMessage)},softCloseHandler:n=>t.close(e,n)})})});return t=>Ot(t,i)}class Li{constructor(t,e){this.data=t,this.isBinary=e}get text(){if(this.isBinary)throw new qi(qi.UNSUPPORTED_DATA,{statusMessage:"expected text"});return this.data.toString("utf-8")}get binary(){if(!this.isBinary)throw new qi(qi.UNSUPPORTED_DATA,{statusMessage:"expected binary"});return this.data}}class zi{constructor(t,{limit:e=-1,signal:n}={}){this.en=new G;const i=e=>{t.off("message",o),t.off("close",r),this.en.close(new Error(e))},r=()=>i("connection closed"),o=(t,n)=>{void 0!==n?this.en.push(new Li(t,n)):"string"==typeof t?this.en.push(new Li(Buffer.from(t,"utf-8"),!1)):this.en.push(new Li(t,!0)),e>0&&0===--e&&this.detach()};this.detach=()=>{},n?.aborted?this.en.close(n.reason):2===t.readyState||3===t.readyState?this.en.close(new Error("connection closed")):(t.on("message",o),t.on("close",r),n?.addEventListener("abort",()=>i("signal aborted")),this.detach=()=>i("WebSocket listener detached"))}next(t){return this.en.shift(t)}[Symbol.asyncIterator](){return this.en[Symbol.asyncIterator]()}}function Wi(t,{timeout:e,signal:n}={}){const i=new zi(t,{limit:1,signal:n});return i.next(e).finally(()=>i.detach())}function Gi(t){const e=at(t);return"GET"===t.method&&(e.D?.has("websocket")??!1)}const Vi=t=>t.headers.origin??lt(t.headers["sec-websocket-origin"]),Zi=(t,e=5e3)=>async n=>{if(!Gi(n))return;const i=await t(n);let r;try{r=await Wi(i,{timeout:e})}catch(t){if((i.readyState??0)>=2)throw St;throw new qi(qi.POLICY_VIOLATION,{statusMessage:"timeout waiting for authentication token",cause:t})}if(r.isBinary)throw new qi(qi.UNSUPPORTED_DATA,{statusMessage:"authentication token must be sent as text"});return r.data.toString("utf-8")};export{G as BlockingQueue,$t as CONTINUE,hn as FileFinder,oe as HTTPError,kt as NEXT_ROUTE,Nt as NEXT_ROUTER,Oe as Property,W as Queue,Kt as Router,St as STOP,Ii as ServerSentEvents,de as WebListener,qi as WebSocketError,Li as WebSocketMessage,zi as WebSocketMessages,pn as acceptBody,Ot as acceptUpgrade,_t as addTeardown,Lt as anyHandler,Cn as checkIfModified,Un as checkIfRange,Ce as clearProperty,Mn as compareETag,rn as compressFileOffline,on as compressFilesInDir,Gt as conditionalErrorHandler,tn as decompressMime,Et as defer,an as emitError,zt as errorHandler,ji as fileServer,V as findCause,qe as generateStrongETag,He as generateWeakETag,Tt as getAbortSignal,jt as getAbsolutePath,Z as getAddressURL,be as getAuthorization,Hn as getBodyJson,Dn as getBodyStream,jn as getBodyText,In as getBodyTextStream,ve as getCharset,yi as getFormData,mi as getFormFields,Ee as getIfRange,nn as getMime,It as getPathParameter,Dt as getPathParameters,Fe as getProperty,ye as getQuery,_e as getRange,bi as getRemainingPathComponents,pe as getSearch,me as getSearchParams,Rn as getTextDecoder,Pn as getTextDecoderStream,Vi as getWebSocketOrigin,Be as hasAuthScope,mt as isSoftClosed,Gi as isWebSocketRequest,fn as jsonErrorHandler,Ji as makeAcceptWebSocket,q as makeAddressTester,gn as makeGetClient,Ae as makeMemo,Ge as makeNegotiator,wn as makeTempFileStorage,Zi as makeWebSocketFallbackTokenFetcher,We as negotiateEncoding,Wi as nextWebSocketMessage,H as parseAddress,mn as proxy,ke as readHTTPDateSeconds,xe as readHTTPInteger,$e as readHTTPKeyValues,Se as readHTTPQualityValues,Te as readHTTPUnquotedCommaSeparated,Qe as readMimeTypes,On as registerCharset,en as registerMime,An as registerUTF32,En as removeForwarded,_n as replaceForwarded,qt as requestHandler,De as requireAuthScope,Me as requireBearerAuth,Ke as resetMime,Ht as restoreAbsolutePath,Tn as sanitiseAndAppendForwarded,Ti as sendCSVStream,Ai as sendFile,Ri as sendJSON,Pi as sendJSONStream,Ni as sendRanges,Hi as setDefaultCacheHeaders,Pe as setProperty,wt as setSoftCloseHandler,xn as simpleAppendForwarded,ki as simplifyRange,ae as toListeners,Wt as typedErrorHandler,Jt as upgradeHandler};
|
package/package.json
CHANGED
package/run.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env -S node --disable-proto=delete --disallow-code-generation-from-strings --force-node-api-uncaught-exceptions-policy --no-addons
|
|
2
|
-
import{readFile as e}from"node:fs/promises";import{join as t,dirname as o,resolve as r}from"node:path";import{createServer as s}from"node:http";import{Router as i,requestHandler as n,addTeardown as a,CONTINUE as f,proxy as c,fileServer as p,getSearch as l,getQuery as h,getPathParameter as u,WebListener as m,compressFilesInDir as d,readMimeTypes as g,decompressMime as w,resetMime as y,registerMime as b}from"./index.js";const x=new Map([["","dir"],["-a","host"],["-b","brotli"],["-c","config-file"],["-C","config-json"],["-d","dir"],["-e","ext"],["-g","gzip"],["-h","help"],["-p","port"],["-P","proxy"],["-v","version"],["br","brotli"],["gz","gzip"],["zst","zstd"]]),$=new Map([["config-file",{type:"string"}],["config-json",{type:"string"}],["dir",{type:"string"}],["ext",{type:"string",multi:!0}],["port",{type:"number"}],["host",{type:"string"}],["zstd",{type:"boolean"}],["brotli",{type:"boolean"}],["gzip",{type:"boolean"}],["deflate",{type:"boolean"}],["proxy",{type:"string"}],["404",{type:"string"}],["spa",{type:"string"}],["mime",{type:"string",multi:!0}],["mime-types",{type:"string",multi:!0}],["write-compressed",{type:"boolean"}],["min-compress",{type:"number"}],["no-serve",{type:"boolean"}],["log",{type:"string"}],["help",{type:"boolean"}],["version",{type:"boolean"}]]),v=new Map([["zstd",{match:"zstd",file:"{file}.zst"}],["brotli",{match:"br",file:"{file}.br"}],["gzip",{match:"gzip",file:"{file}.gz"}],["deflate",{match:"deflate",file:"{file}.deflate"}]]);const S=e=>(t,o)=>{if(t!==e)throw new A(`expected ${JSON.stringify(e)}`,o,8);return e},z=e=>(t,o)=>{if(!e.has(t))throw new A(`expected one of ${JSON.stringify(e)}`,o,7);return t},k=e=>(t,o)=>{const r=[];let s=9;for(const i of e)try{return i(t,o)}catch(e){if(e instanceof A){if(e.p>s)continue;e.p!==s&&(s=e.p,r.length=0)}else s=-1;r.push(e)}throw 1===r.length?r[0]:new AggregateError(r)},j=e=>(t,o)=>{if(!Array.isArray(t))throw new A("expected list, got "+typeof t,o);return t.map((t,r)=>e(t,{...o,path:`${o.path}[${r}]`}))},N=(e,t)=>{if("boolean"!=typeof e)throw new A("expected boolean, got "+typeof e,t);return e},E=(e,t,o)=>(r,s)=>{if("number"!=typeof r)throw new A("expected number, got "+typeof r,s);if(e&&(0|r)!==r)throw new A(`expected integer, got ${r}`,s);if("number"==typeof t&&r<t)throw new A(`value cannot be less than ${t}`,s);if("number"==typeof o&&r>o)throw new A(`value cannot be greater than ${o}`,s);return r},O=(e,t)=>(s,i)=>{if("string"!=typeof s)throw new A("expected string, got "+typeof s,i);if(e&&!e.test(s))throw new A(`expected string matching ${e}`,i);if("uri-reference"===t&&i.file){if(s.startsWith("file://"))return"file://"+r(o(i.file),s.substring(7));if(!s.includes("://"))return r(o(i.file),s)}return s},P=(e,t,o)=>(r,s)=>{if("object"!=typeof r)throw new A("expected object, got "+typeof r,s);if(!r)throw new A("expected object, got null",s);if(Array.isArray(r))throw new A("expected object, got list",s);const i={},n=new Set;for(const[o,a]of Object.entries(r)){n.add(o);const r=(e.get(o)??t)(a,{...s,path:`${s.path}.${o}`});void 0!==r&&(i[o]=r)}for(const e of o)if(void 0===i[e])throw new A(`missing required property ${JSON.stringify(e)}`,s);for(const[t,o]of e)if(!n.has(t)){const e=o(void 0,{...s,path:`${s.path}.${t}`});void 0!==e&&(i[t]=e)}return i},T=e=>e,J=(e,t)=>{throw new A("unknown property",t)};class A extends Error{constructor(e,t,o=0){super(`${e} at ${t.path||"root"}`),this.p=o}}function I(e,t){return t.replaceAll(/\$\{([^${}:]+)(?::-(([^}\\]|\\.)*))?\}/g,(t,o,r)=>{let s;return s="?"===o?l(e):"?"===o[0]?h(e,o.substring(1)):u(e,o),"string"==typeof s?s:Array.isArray(s)?s.join("/"):r??""})}class q{constructor(e,t){this.t=!1,this.o=!1,this.i=!1,this.l=e,this.h=t,this.u=new Map}async set(e){if(!this.o&&!this.i)try{this.o=!0;const t=new Set,o=[];for(let r=0;r<e.length;++r){const s=e[r],i=s.port;i<=0||i>65535?this.l(0,`servers[${r}] must have a specific port from 1 to 65535`):t.has(i)?this.l(0,`skipping servers[${r}] because port ${i} has already been defined`):(t.add(i),o.push(async()=>{const e=await this.m(s,this.u.get(i));e?this.u.set(i,e):this.u.delete(i)}))}this.t||=o.length>0;for(const[e,r]of this.u)t.has(e)||(o.push(r.close),this.u.delete(e));await Promise.all(o.map(e=>e())),this.i?this.$():this.u.size?this.l(1,"all servers ready"):this.l(1,"no servers configured")}finally{this.o=!1}}async m({port:e,host:t,options:o,mount:r},l){const h=this.h("34",`http://${t}:${e}`),u=await(async(e,t=()=>{})=>{const o=new i;o.use(n((e,o)=>{const r=Date.now();return a(e,()=>{const s=Date.now()-r;t({method:e.method??"GET",path:e.url??"/",status:o.statusCode,duration:s})}),f}));for(const t of e)switch(t.type){case"files":"/dev/null"!==t.dir&&o.mount(t.path,await p(t.dir,t.options));break;case"proxy":o.mount(t.path,c(t.target,t.options));break;case"fixture":const e=(e,o)=>{for(const[r,s]of Object.entries(t.headers))"string"==typeof s?o.setHeader(r,I(e,s)):"number"==typeof s?o.setHeader(r,s):o.setHeader(r,s.map(t=>I(e,t)));o.statusCode=t.status,o.end(I(e,t.body))};"GET"===t.method&&o.onRequest("HEAD",t.path,e),o.onRequest(t.method,t.path,e);break;case"redirect":o.at(t.path,n((e,o)=>{o.setHeader("location",I(e,t.target)),o.statusCode=t.status,o.end()}))}return o})(r,o.logRequests?e=>{const t=this.h("1",e.method.replaceAll(/[^a-zA-Z0-9\-_]/g,"?")),o=encodeURI(e.path),r=this.h(C[e.status/100|0]??"",String(e.status)),s=this.h("2",`(${e.duration}ms)`);this.l(0,`${h} ${t} ${o} ${r} ${s}`)}:()=>{}),d=new m(u);let g,w;if(d.addEventListener("error",({detail:{action:e,error:t,request:o}})=>{this.l(0,`${h} ${this.h("91","error")}: ${e} ${o?.url} ${t}`)}),l&&t===l.host&&((e,t)=>{for(const o of M)if(e[o]!==t[o])return!1;return!0})(o,l.options))g=l.server,this.l(2,`${h} updated`),l.detach();else{if(l?(this.l(2,`${h} ${this.h("2","restarting (step 1: shutdown)")}`),await l.close(),this.l(2,`${h} ${this.h("2","restarting (step 2: start)")}`)):this.l(2,`${h} ${this.h("2","starting")}`),this.i)return;g=s(o),g.setTimeout(o.socketTimeout),w=D(g,e,t,o.backlog)}const y=d.attach(g,o);return w&&(await w,await new Promise(e=>setTimeout(e,0)),this.l(2,`${h} ready`)),{host:t,options:o,server:g,detach:()=>y("restart",o.restartTimeout),close:()=>new Promise(e=>{const t=y("shutdown",o.shutdownTimeout,!0,()=>{g.close(()=>{this.l(2,`${h} closed`),e()}),g.closeAllConnections()}).countConnections();t>0&&this.l(2,`${h} ${this.h("2",`closing (remaining connections: ${t})`)}`)})}}async $(){this.u.size&&(this.l(2,this.h("2","shutting down")),await Promise.all([...this.u.values()].map(e=>e.close()))),this.t&&this.l(2,"shutdown complete")}shutdown(){this.i||(this.i=!0,this.o||this.$())}}const C=["","37","32","36","31","41;97"],D=async(e,t,o,r=511)=>new Promise((s,i)=>{e.once("error",i),e.listen(t,o,r,()=>{e.off("error",i),s()})}),M=["requestTimeout","keepAliveTimeout","keepAliveTimeoutBuffer","connectionsCheckingInterval","headersTimeout","highWaterMark","maxHeaderSize","noDelay","requireHostHeader","keepAlive","keepAliveInitialDelay","uniqueHeaders","backlog","socketTimeout"];function G(e){return e.reduce((e,t)=>({rawSize:e.rawSize+t.rawSize,bestSize:e.bestSize+t.bestSize,created:e.created+t.created}),{rawSize:0,bestSize:0,created:0})}const H=e=>e<2e3?`${e}B`.padStart(8," "):`${(e/1024).toFixed(1)}kB`.padStart(8," "),R=["none","ready","progress"];process.on("SIGUSR1",()=>{});let B=2;const U=(e,t)=>e<=B&&process.stderr.write(t+"\n");function L(e){process.stdin.destroy(),U(0,e instanceof Error?e.message:String(e))}process.on("unhandledRejection",L),process.on("uncaughtException",L);const W=process.stderr.isTTY&&!process.env.NO_COLOR?(e,t)=>e?`\x1b[${e}m${t}\x1b[0m`:t:(e,t)=>t,_=(e=>{const t=[];for(let o=0;o<e.length;++o){const r=e[o];if("--"===r)continue;const s=/^--([^ =\-][^ =]*)=(.*)$/.exec(r);if(s){t.push([s[1],s[2]]);continue}const i=/^-([^ =]*)([^ =])=(.*)$/.exec(r);if(i&&"-"!==r[1]){for(const e of i[1])t.push(["-"+e,""]);t.push(["-"+i[2],i[3]]);continue}if("-"!==r[0]||"-"===r){if(0!==o)throw new Error(`value without key: ${r}`);t.push(["",r]);continue}let n=e[o+1];if(n&&"-"===n[0]&&n.length>1&&(n=void 0),void 0!==n&&++o,"-"===r[1])t.push([r.slice(2),n??""]);else{for(const e of r.slice(1,r.length-1))t.push(["-"+e,""]);t.push(["-"+r[r.length-1],n??""])}}const o=new Map;for(const[e,r]of t){const t=(x.get(e)??e).toLowerCase(),s=$.get(t);if(!s)throw new Error(`unknown flag: ${e}`);let i;switch(s.type){case"string":i=r;break;case"number":i=Number.parseFloat(r);break;case"boolean":i=["","on","true","yes","y","1"].includes(r.toLowerCase())}if(s.multi){let e=o.get(t);e||(e=[],o.set(t,e)),e.push(i)}else{if(o.has(t))throw new Error(`multiple values for ${t}`);o.set(t,i)}}return o})(process.argv.slice(2));if(_.get("version")||_.get("help")){const r=JSON.parse(await e(t(o(new URL(import.meta.url).pathname),"package.json"),"utf-8"));process.stdout.write(`${r.name} ${r.version}\n`),_.get("help")&&process.stdout.write((F=r.name,["","HTTP/1.1 server for Node.js","","Serves the current directory on port 8080 by default.","When running, send SIGINT (Ctrl+C) to stop.","Send SIGHUP or press enter to reload config.","",` npx ${F} -- [dir] [flags]`,"","Options:"," --config-file=..., -c Path to a JSON configuration file to use (see below)"," --config-json=..., -C Inline JSON configuration to use (see below)",' --port=..., -p The port to bind to. Default "8080"',' --host=..., -a The host address to bind to. Default "localhost"',' --dir=... The directory to serve. Default "."'," --ext=... Implicit file extension to attempt if the requested file"," does not exist (can be specified multiple times)"," --404=... File to use for file-not-found, with status 404"," --spa=... File to use for file-not-found, with status 200"," (e.g. to serve an index file for Single-Page-Apps)"," --zstd, --zst Serve .zst files if zstd compression is requested"," --brotli, --br, -b Serve .br files if brotli compression is requested"," --gzip, --gz, -g Serve .gz files if gzip compression is requested"," --deflate Serve .deflate files if deflate compression is requested"," --proxy=..., -P Proxy requests which match no files to this server"," --mime=... Extra file-extension-to-mime-types to use, in the format",' "ext1=mime1;ext2=mime2" (e.g. "txt=text/plain")'," --mime-types=... Path to an Apache .types file of mime types to register"," --write-compressed Generate and save zstd, brotli, gzip, or deflate files"," for each served file before starting"," --min-compress=... The minimum number of bytes that compression must save,",' otherwise the file is not written. Default "300"'," --no-serve Stop after validating the configuration and optionally"," writing any compressed files",' --log=... "none" / "ready" / "progress" / "full". Set the logging',' level. "ready" prints only the "all servers ready" line,',' "progress" prints server startup and shutdown progress,',' and "full" logs all requests. Default "full"'," --help, -h Print this message and exit"," --version, -v Print the current version and exit","","JSON Configuration:","","JSON offers a more powerful way to configure the server. You can define one or","more servers (one per port), each with its own set of mounted handlers.","Example definition:",""," {",' "servers": ['," {",' "port": 9000,',' "mount": [',' { "type": "files", "dir": "." }',' { "type": "fixture", "method": "GET", "path": "/hello.txt", "body": "Hi!" }',' { "type": "proxy", "target": "https://example.com" }'," ]"," }"," ],",' "mime": ["foo=application/x-foo"],'," }","","All CLI flags are compatible with JSON configuration except --dir and --proxy.","--port is not compatible with JSON configurations with more than one server.","","MIME definitions:","","When defining mime types, some shorthands are available:","- multiple mappings separated by semicolons: foo=text/x-foo;bar=text/x-bar","- multiple file extensions separated by commas: foo,bar=text/plain","- use the file extension in the mime type with {ext}: css,csv=text/{ext}","- optional parts in brackets: jp(e)g,tif(f)=image/{ext}"," ({ext} always maps to the full name, so the example maps .jpg to image/jpeg)","","When using an apache .types file, each line contains a mime type, any amount of","whitespace, then a list of space-separated extensions (without a dot). Lines","starting with # are ignored as comments.","","Example usage:","",` npx ${F} . --port 3000 --gzip --mime="foo=text/x-foo" --mime="bar=text/x-bar"`,"",` npx ${F} /dev/null --proxy https://example.com`,"",` npx ${F} -C '{"servers":[{"port":8080,"mount":[{"type":"files","dir":"."}]}]}'`,"",` npx ${F} . --write-compressed --min-compress 500 --brotli --gzip`,"",` npx ${F} . --write-compressed --brotli --no-serve`]).join("\n")+"\n"),process.exit(0)}var F;(async()=>{const r=new q(U,W);process.on("unhandledRejection",()=>r.shutdown()),process.on("uncaughtException",()=>r.shutdown());const s=function(e){const t=o=>{const r=o.$ref;if(r&&r.startsWith("#/$defs/")){const t=e.$defs[r.substring(8)];if(!t)throw new Error(`unable to find ${r} in schema`);o={...t,...o}}const s=((e,t)=>{if(void 0!==e.const)return S(e.const);if(e.enum)return z(new Set(e.enum));if(e.anyOf)return k(e.anyOf.map(t));switch(e.type){case"array":return j(t(e.items));case"boolean":return N;case"integer":return E(!0,e.minimum,e.maximum);case"number":return E(!1,e.minimum,e.maximum);case"object":const o=e.additionalProperties??!0;return P(new Map(Object.entries(e.properties??{}).map(([e,o])=>[e,t(o)])),"object"==typeof o?t(o):o?T:J,e.required??[]);case"string":let r=null;return e.pattern&&(r=new RegExp(e.pattern)),O(r,e.format??"");default:throw new Error(`unknown part type ${JSON.stringify(e)}`)}})(o,t);if(void 0!==o.default){const e=JSON.stringify(o.default);return(t,o)=>s(void 0===t?JSON.parse(e):t,o)}return(e,t)=>void 0===e?void 0:s(e,t)};return t(e)}(await(async()=>JSON.parse(await e(t(o(new URL(import.meta.url).pathname),"schema.json"),"utf-8")))());function i(){process.stdin.destroy(),r.shutdown()}async function n(){const t=await(async(t,o)=>{const r=e=>o.get(e)??[],s=e=>o.get(e),i=e=>o.get(e),n=s("config-file"),a=s("config-json"),f=i("port"),c=s("host"),p=s("dir")||".",l=r("ext").map(e=>e.startsWith(".")?e:`.${e}`),h=s("404"),u=s("spa"),m=s("proxy"),d=i("min-compress"),g=r("mime"),w=r("mime-types"),y=s("log");if(Number(Boolean(n))+Number(Boolean(a))+Number(Boolean(m))>1)throw new Error("multiple config files are not supported");let b;if(n)b=t(JSON.parse(await e(n,"utf-8")),{file:n,path:""});else if(a)b=t(JSON.parse(a),{file:"",path:""});else{let e;u?e={statusCode:200,filePath:u}:h&&(e={statusCode:404,filePath:h});const o=[{type:"files",dir:p,options:{fallback:e}}];m&&o.push({type:"proxy",target:m}),b=t({servers:[{port:8080,mount:o}]},{file:"",path:""})}const x=1===b.servers.length?b.servers[0]:void 0;if(void 0!==f){if((0|f)!==f)throw new Error("port must be an integer");if(!x)throw new Error("cannot specify port on commandline when defining multiple servers");x.port=f}if(void 0!==c)for(const e of b.servers)e.host=c;const $=(e,t)=>{for(const o of b.servers)for(const r of o.mount)if("files"===r.type){r.options.negotiation??=[];let o=r.options.negotiation.find(t=>t.type===e);o||(o={type:e,options:[]},r.options.negotiation=[...r.options.negotiation,o]),o.options.find(e=>e.match===t.match)||o.options.push(t)}};for(const[e,t]of v)o.get(e)&&$("encoding",t);if(l.length)for(const e of b.servers)for(const t of e.mount)"files"===t.type&&(t.options.implicitSuffixes=l);switch((g.length||w.length)&&(Array.isArray(b.mime)||(b.mime?b.mime=[b.mime]:b.mime=[]),b.mime.push(...g),b.mime.push(...w.map(e=>`file://${e}`))),o.get("write-compressed")&&(b.writeCompressed=!0),void 0!==d&&(b.minCompress=d),o.get("no-serve")&&(b.noServe=!0),y){case"none":case"ready":case"progress":b.log=y;for(const e of b.servers)e.options.logRequests=!1;break;case"full":b.log="progress"}return b})(s,_);B=R.indexOf(t.log),await(async t=>{const o=[];for(const r of Array.isArray(t)?t:[t])"string"!=typeof r?o.push(new Map(Object.entries(r))):r.startsWith("file://")?o.push(g(await e(r.substring(7),"utf-8"))):o.push(w(r));y();for(const e of o)b(e)})(t.mime),t.writeCompressed&&await(async(e,t,o)=>{let r=0;for(const s of e)for(const e of s.mount)if("files"===e.type){const s=e.options.negotiation?.find(e=>"encoding"===e.type)?.options;if(!s?.length){o(2,`skipping ${e.dir} because no compression is configured`);continue}o(2,`compressing files in ${e.dir} using ${s.map(e=>e.match).join(", ")}`);const i=await d(e.dir,s,t),n=G(i.filter(({mime:e})=>e.startsWith("text/"))),a=G(i.filter(({mime:e})=>!e.startsWith("text/")));o(2,`text: ${H(n.rawSize)} / ${H(n.bestSize)} compressed`),o(2,`other: ${H(a.rawSize)} / ${H(a.bestSize)} compressed`),r+=n.created+a.created}o(2,`${((e,t,o=t+"s")=>1===e?`1 ${t}`:`${e} ${o}`)(r,"compressed file")} written`)})(t.servers,t.minCompress,U),t.noServe?i():r.set(t.servers)}function a(){return U(2,"refreshing config"),n()}n(),process.on("SIGHUP",()=>a()),process.stdin.on("data",e=>{e.includes("\n")&&a()}),process.on("SIGINT",()=>{U(2,""),i()})})();
|
|
2
|
+
import{readFile as e}from"node:fs/promises";import{join as t,dirname as o,resolve as r}from"node:path";import{createServer as s}from"node:http";import{Router as i,requestHandler as n,addTeardown as a,CONTINUE as f,proxy as c,fileServer as p,getSearch as l,getQuery as h,getPathParameter as u,WebListener as m,findCause as d,HTTPError as g,compressFilesInDir as w,readMimeTypes as y,decompressMime as b,resetMime as x,registerMime as $}from"./index.js";const v=new Map([["","dir"],["-a","host"],["-b","brotli"],["-c","config-file"],["-C","config-json"],["-d","dir"],["-e","ext"],["-g","gzip"],["-h","help"],["-p","port"],["-P","proxy"],["-v","version"],["br","brotli"],["gz","gzip"],["zst","zstd"]]),S=new Map([["config-file",{type:"string"}],["config-json",{type:"string"}],["dir",{type:"string"}],["ext",{type:"string",multi:!0}],["port",{type:"number"}],["host",{type:"string"}],["zstd",{type:"boolean"}],["brotli",{type:"boolean"}],["gzip",{type:"boolean"}],["deflate",{type:"boolean"}],["proxy",{type:"string"}],["404",{type:"string"}],["spa",{type:"string"}],["mime",{type:"string",multi:!0}],["mime-types",{type:"string",multi:!0}],["write-compressed",{type:"boolean"}],["min-compress",{type:"number"}],["no-serve",{type:"boolean"}],["log",{type:"string"}],["help",{type:"boolean"}],["version",{type:"boolean"}]]),z=new Map([["zstd",{match:"zstd",file:"{file}.zst"}],["brotli",{match:"br",file:"{file}.br"}],["gzip",{match:"gzip",file:"{file}.gz"}],["deflate",{match:"deflate",file:"{file}.deflate"}]]);const k=e=>(t,o)=>{if(t!==e)throw new q(`expected ${JSON.stringify(e)}`,o,8);return e},j=e=>(t,o)=>{if(!e.has(t))throw new q(`expected one of ${JSON.stringify(e)}`,o,7);return t},N=e=>(t,o)=>{const r=[];let s=9;for(const i of e)try{return i(t,o)}catch(e){if(e instanceof q){if(e.p>s)continue;e.p!==s&&(s=e.p,r.length=0)}else s=-1;r.push(e)}throw 1===r.length?r[0]:new AggregateError(r)},E=e=>(t,o)=>{if(!Array.isArray(t))throw new q("expected list, got "+typeof t,o);return t.map((t,r)=>e(t,{...o,path:`${o.path}[${r}]`}))},O=(e,t)=>{if("boolean"!=typeof e)throw new q("expected boolean, got "+typeof e,t);return e},P=(e,t,o)=>(r,s)=>{if("number"!=typeof r)throw new q("expected number, got "+typeof r,s);if(e&&(0|r)!==r)throw new q(`expected integer, got ${r}`,s);if("number"==typeof t&&r<t)throw new q(`value cannot be less than ${t}`,s);if("number"==typeof o&&r>o)throw new q(`value cannot be greater than ${o}`,s);return r},T=(e,t)=>(s,i)=>{if("string"!=typeof s)throw new q("expected string, got "+typeof s,i);if(e&&!e.test(s))throw new q(`expected string matching ${e}`,i);if("uri-reference"===t&&i.file){if(s.startsWith("file://"))return"file://"+r(o(i.file),s.substring(7));if(!s.includes("://"))return r(o(i.file),s)}return s},J=(e,t,o)=>(r,s)=>{if("object"!=typeof r)throw new q("expected object, got "+typeof r,s);if(!r)throw new q("expected object, got null",s);if(Array.isArray(r))throw new q("expected object, got list",s);const i={},n=new Set;for(const[o,a]of Object.entries(r)){n.add(o);const r=(e.get(o)??t)(a,{...s,path:`${s.path}.${o}`});void 0!==r&&(i[o]=r)}for(const e of o)if(void 0===i[e])throw new q(`missing required property ${JSON.stringify(e)}`,s);for(const[t,o]of e)if(!n.has(t)){const e=o(void 0,{...s,path:`${s.path}.${t}`});void 0!==e&&(i[t]=e)}return i},A=e=>e,I=(e,t)=>{throw new q("unknown property",t)};class q extends Error{constructor(e,t,o=0){super(`${e} at ${t.path||"root"}`),this.p=o}}function C(e,t){return t.replaceAll(/\$\{([^${}:]+)(?::-(([^}\\]|\\.)*))?\}/g,(t,o,r)=>{let s;return s="?"===o?l(e):"?"===o[0]?h(e,o.substring(1)):u(e,o),"string"==typeof s?s:Array.isArray(s)?s.join("/"):r??""})}class D{constructor(e,t){this.t=!1,this.o=!1,this.i=!1,this.l=e,this.h=t,this.u=new Map}async set(e){if(!this.o&&!this.i)try{this.o=!0;const t=new Set,o=[];for(let r=0;r<e.length;++r){const s=e[r],i=s.port;i<=0||i>65535?this.l(0,`servers[${r}] must have a specific port from 1 to 65535`):t.has(i)?this.l(0,`skipping servers[${r}] because port ${i} has already been defined`):(t.add(i),o.push(async()=>{const e=await this.m(s,this.u.get(i));e?this.u.set(i,e):this.u.delete(i)}))}this.t||=o.length>0;for(const[e,r]of this.u)t.has(e)||(o.push(r.close),this.u.delete(e));await Promise.all(o.map(e=>e())),this.i?this.$():this.u.size?this.l(1,"all servers ready"):this.l(1,"no servers configured")}finally{this.o=!1}}async m({port:e,host:t,options:o,mount:r},l){const h=this.h("34",`http://${t}:${e}`),u=await(async(e,t=()=>{})=>{const o=new i;o.use(n((e,o)=>{const r=Date.now();return a(e,()=>{const s=Date.now()-r;t({method:e.method??"GET",path:e.url??"/",status:o.statusCode,duration:s})}),f}));for(const t of e)switch(t.type){case"files":"/dev/null"!==t.dir&&o.mount(t.path,await p(t.dir,t.options));break;case"proxy":o.mount(t.path,c(t.target,t.options));break;case"fixture":const e=(e,o)=>{for(const[r,s]of Object.entries(t.headers))"string"==typeof s?o.setHeader(r,C(e,s)):"number"==typeof s?o.setHeader(r,s):o.setHeader(r,s.map(t=>C(e,t)));o.statusCode=t.status,o.end(C(e,t.body))};"GET"===t.method&&o.onRequest("HEAD",t.path,e),o.onRequest(t.method,t.path,e);break;case"redirect":o.at(t.path,n((e,o)=>{o.setHeader("location",C(e,t.target)),o.statusCode=t.status,o.end()}))}return o})(r,o.logRequests?e=>{const t=this.h("1",e.method.replaceAll(/[^a-zA-Z0-9\-_]/g,"?")),o=encodeURI(e.path),r=this.h(M[e.status/100|0]??"",String(e.status)),s=this.h("2",`(${e.duration}ms)`);this.l(0,`${h} ${t} ${o} ${r} ${s}`)}:()=>{}),w=new m(u);let y,b;if(w.addEventListener("error",e=>{e.preventDefault();const{error:t,context:o,request:r}=e.detail;(d(t,g)?.statusCode??500)>=500&&this.l(0,`${h} ${this.h("91","error")}: ${o} ${r?.url} ${t}`)}),l&&t===l.host&&((e,t)=>{for(const o of H)if(e[o]!==t[o])return!1;return!0})(o,l.options))y=l.server,this.l(2,`${h} updated`),l.detach();else{if(l?(this.l(2,`${h} ${this.h("2","restarting (step 1: shutdown)")}`),await l.close(),this.l(2,`${h} ${this.h("2","restarting (step 2: start)")}`)):this.l(2,`${h} ${this.h("2","starting")}`),this.i)return;y=s(o),y.setTimeout(o.socketTimeout),b=G(y,e,t,o.backlog)}const x=w.attach(y,o);return b&&(await b,await new Promise(e=>setTimeout(e,0)),this.l(2,`${h} ready`)),{host:t,options:o,server:y,detach:()=>x("restart",o.restartTimeout),close:()=>new Promise(e=>{const t=x("shutdown",o.shutdownTimeout,!0,()=>{y.close(()=>{this.l(2,`${h} closed`),e()}),y.closeAllConnections()}).countConnections();t>0&&this.l(2,`${h} ${this.h("2",`closing (remaining connections: ${t})`)}`)})}}async $(){this.u.size&&(this.l(2,this.h("2","shutting down")),await Promise.all([...this.u.values()].map(e=>e.close()))),this.t&&this.l(2,"shutdown complete")}shutdown(){this.i||(this.i=!0,this.o||this.$())}}const M=["","37","32","36","31","41;97"],G=async(e,t,o,r=511)=>new Promise((s,i)=>{e.once("error",i),e.listen(t,o,r,()=>{e.off("error",i),s()})}),H=["requestTimeout","keepAliveTimeout","keepAliveTimeoutBuffer","connectionsCheckingInterval","headersTimeout","highWaterMark","maxHeaderSize","noDelay","requireHostHeader","keepAlive","keepAliveInitialDelay","uniqueHeaders","backlog","socketTimeout"];function R(e){return e.reduce((e,t)=>({rawSize:e.rawSize+t.rawSize,bestSize:e.bestSize+t.bestSize,created:e.created+t.created}),{rawSize:0,bestSize:0,created:0})}const B=e=>e<2e3?`${e}B`.padStart(8," "):`${(e/1024).toFixed(1)}kB`.padStart(8," "),U=["none","ready","progress"];process.on("SIGUSR1",()=>{});let L=2;const W=(e,t)=>e<=L&&process.stderr.write(t+"\n");function _(e){process.stdin.destroy(),W(0,e instanceof Error?e.message:String(e))}process.on("unhandledRejection",_),process.on("uncaughtException",_);const F=process.stderr.isTTY&&!process.env.NO_COLOR?(e,t)=>e?`\x1b[${e}m${t}\x1b[0m`:t:(e,t)=>t,Y=(e=>{const t=[];for(let o=0;o<e.length;++o){const r=e[o];if("--"===r)continue;const s=/^--([^ =\-][^ =]*)=(.*)$/.exec(r);if(s){t.push([s[1],s[2]]);continue}const i=/^-([^ =]*)([^ =])=(.*)$/.exec(r);if(i&&"-"!==r[1]){for(const e of i[1])t.push(["-"+e,""]);t.push(["-"+i[2],i[3]]);continue}if("-"!==r[0]||"-"===r){if(0!==o)throw new Error(`value without key: ${r}`);t.push(["",r]);continue}let n=e[o+1];if(n&&"-"===n[0]&&n.length>1&&(n=void 0),void 0!==n&&++o,"-"===r[1])t.push([r.slice(2),n??""]);else{for(const e of r.slice(1,r.length-1))t.push(["-"+e,""]);t.push(["-"+r[r.length-1],n??""])}}const o=new Map;for(const[e,r]of t){const t=(v.get(e)??e).toLowerCase(),s=S.get(t);if(!s)throw new Error(`unknown flag: ${e}`);let i;switch(s.type){case"string":i=r;break;case"number":i=Number.parseFloat(r);break;case"boolean":i=["","on","true","yes","y","1"].includes(r.toLowerCase())}if(s.multi){let e=o.get(t);e||(e=[],o.set(t,e)),e.push(i)}else{if(o.has(t))throw new Error(`multiple values for ${t}`);o.set(t,i)}}return o})(process.argv.slice(2));if(Y.get("version")||Y.get("help")){const r=JSON.parse(await e(t(o(new URL(import.meta.url).pathname),"package.json"),"utf-8"));process.stdout.write(`${r.name} ${r.version}\n`),Y.get("help")&&process.stdout.write((Z=r.name,["","HTTP/1.1 server for Node.js","","Serves the current directory on port 8080 by default.","When running, send SIGINT (Ctrl+C) to stop.","Send SIGHUP or press enter to reload config.","",` npx ${Z} -- [dir] [flags]`,"","Options:"," --config-file=..., -c Path to a JSON configuration file to use (see below)"," --config-json=..., -C Inline JSON configuration to use (see below)",' --port=..., -p The port to bind to. Default "8080"',' --host=..., -a The host address to bind to. Default "localhost"',' --dir=... The directory to serve. Default "."'," --ext=... Implicit file extension to attempt if the requested file"," does not exist (can be specified multiple times)"," --404=... File to use for file-not-found, with status 404"," --spa=... File to use for file-not-found, with status 200"," (e.g. to serve an index file for Single-Page-Apps)"," --zstd, --zst Serve .zst files if zstd compression is requested"," --brotli, --br, -b Serve .br files if brotli compression is requested"," --gzip, --gz, -g Serve .gz files if gzip compression is requested"," --deflate Serve .deflate files if deflate compression is requested"," --proxy=..., -P Proxy requests which match no files to this server"," --mime=... Extra file-extension-to-mime-types to use, in the format",' "ext1=mime1;ext2=mime2" (e.g. "txt=text/plain")'," --mime-types=... Path to an Apache .types file of mime types to register"," --write-compressed Generate and save zstd, brotli, gzip, or deflate files"," for each served file before starting"," --min-compress=... The minimum number of bytes that compression must save,",' otherwise the file is not written. Default "300"'," --no-serve Stop after validating the configuration and optionally"," writing any compressed files",' --log=... "none" / "ready" / "progress" / "full". Set the logging',' level. "ready" prints only the "all servers ready" line,',' "progress" prints server startup and shutdown progress,',' and "full" logs all requests. Default "full"'," --help, -h Print this message and exit"," --version, -v Print the current version and exit","","JSON Configuration:","","JSON offers a more powerful way to configure the server. You can define one or","more servers (one per port), each with its own set of mounted handlers.","Example definition:",""," {",' "servers": ['," {",' "port": 9000,',' "mount": [',' { "type": "files", "dir": "." }',' { "type": "fixture", "method": "GET", "path": "/hello.txt", "body": "Hi!" }',' { "type": "proxy", "target": "https://example.com" }'," ]"," }"," ],",' "mime": ["foo=application/x-foo"],'," }","","All CLI flags are compatible with JSON configuration except --dir and --proxy.","--port is not compatible with JSON configurations with more than one server.","","MIME definitions:","","When defining mime types, some shorthands are available:","- multiple mappings separated by semicolons: foo=text/x-foo;bar=text/x-bar","- multiple file extensions separated by commas: foo,bar=text/plain","- use the file extension in the mime type with {ext}: css,csv=text/{ext}","- optional parts in brackets: jp(e)g,tif(f)=image/{ext}"," ({ext} always maps to the full name, so the example maps .jpg to image/jpeg)","","When using an apache .types file, each line contains a mime type, any amount of","whitespace, then a list of space-separated extensions (without a dot). Lines","starting with # are ignored as comments.","","Example usage:","",` npx ${Z} . --port 3000 --gzip --mime="foo=text/x-foo" --mime="bar=text/x-bar"`,"",` npx ${Z} /dev/null --proxy https://example.com`,"",` npx ${Z} -C '{"servers":[{"port":8080,"mount":[{"type":"files","dir":"."}]}]}'`,"",` npx ${Z} . --write-compressed --min-compress 500 --brotli --gzip`,"",` npx ${Z} . --write-compressed --brotli --no-serve`]).join("\n")+"\n"),process.exit(0)}var Z;(async()=>{const r=new D(W,F);process.on("unhandledRejection",()=>r.shutdown()),process.on("uncaughtException",()=>r.shutdown());const s=function(e){const t=o=>{const r=o.$ref;if(r&&r.startsWith("#/$defs/")){const t=e.$defs[r.substring(8)];if(!t)throw new Error(`unable to find ${r} in schema`);o={...t,...o}}const s=((e,t)=>{if(void 0!==e.const)return k(e.const);if(e.enum)return j(new Set(e.enum));if(e.anyOf)return N(e.anyOf.map(t));switch(e.type){case"array":return E(t(e.items));case"boolean":return O;case"integer":return P(!0,e.minimum,e.maximum);case"number":return P(!1,e.minimum,e.maximum);case"object":const o=e.additionalProperties??!0;return J(new Map(Object.entries(e.properties??{}).map(([e,o])=>[e,t(o)])),"object"==typeof o?t(o):o?A:I,e.required??[]);case"string":let r=null;return e.pattern&&(r=new RegExp(e.pattern)),T(r,e.format??"");default:throw new Error(`unknown part type ${JSON.stringify(e)}`)}})(o,t);if(void 0!==o.default){const e=JSON.stringify(o.default);return(t,o)=>s(void 0===t?JSON.parse(e):t,o)}return(e,t)=>void 0===e?void 0:s(e,t)};return t(e)}(await(async()=>JSON.parse(await e(t(o(new URL(import.meta.url).pathname),"schema.json"),"utf-8")))());function i(){process.stdin.destroy(),r.shutdown()}async function n(){const t=await(async(t,o)=>{const r=e=>o.get(e)??[],s=e=>o.get(e),i=e=>o.get(e),n=s("config-file"),a=s("config-json"),f=i("port"),c=s("host"),p=s("dir")||".",l=r("ext").map(e=>e.startsWith(".")?e:`.${e}`),h=s("404"),u=s("spa"),m=s("proxy"),d=i("min-compress"),g=r("mime"),w=r("mime-types"),y=s("log");if(Number(Boolean(n))+Number(Boolean(a))+Number(Boolean(m))>1)throw new Error("multiple config files are not supported");let b;if(n)b=t(JSON.parse(await e(n,"utf-8")),{file:n,path:""});else if(a)b=t(JSON.parse(a),{file:"",path:""});else{let e;u?e={statusCode:200,filePath:u}:h&&(e={statusCode:404,filePath:h});const o=[{type:"files",dir:p,options:{fallback:e}}];m&&o.push({type:"proxy",target:m}),b=t({servers:[{port:8080,mount:o}]},{file:"",path:""})}const x=1===b.servers.length?b.servers[0]:void 0;if(void 0!==f){if((0|f)!==f)throw new Error("port must be an integer");if(!x)throw new Error("cannot specify port on commandline when defining multiple servers");x.port=f}if(void 0!==c)for(const e of b.servers)e.host=c;const $=(e,t)=>{for(const o of b.servers)for(const r of o.mount)if("files"===r.type){r.options.negotiation??=[];let o=r.options.negotiation.find(t=>t.type===e);o||(o={type:e,options:[]},r.options.negotiation=[...r.options.negotiation,o]),o.options.find(e=>e.match===t.match)||o.options.push(t)}};for(const[e,t]of z)o.get(e)&&$("encoding",t);if(l.length)for(const e of b.servers)for(const t of e.mount)"files"===t.type&&(t.options.implicitSuffixes=l);switch((g.length||w.length)&&(Array.isArray(b.mime)||(b.mime?b.mime=[b.mime]:b.mime=[]),b.mime.push(...g),b.mime.push(...w.map(e=>`file://${e}`))),o.get("write-compressed")&&(b.writeCompressed=!0),void 0!==d&&(b.minCompress=d),o.get("no-serve")&&(b.noServe=!0),y){case"none":case"ready":case"progress":b.log=y;for(const e of b.servers)e.options.logRequests=!1;break;case"full":b.log="progress"}return b})(s,Y);L=U.indexOf(t.log),await(async t=>{const o=[];for(const r of Array.isArray(t)?t:[t])"string"!=typeof r?o.push(new Map(Object.entries(r))):r.startsWith("file://")?o.push(y(await e(r.substring(7),"utf-8"))):o.push(b(r));x();for(const e of o)$(e)})(t.mime),t.writeCompressed&&await(async(e,t,o)=>{let r=0;for(const s of e)for(const e of s.mount)if("files"===e.type){const s=e.options.negotiation?.find(e=>"encoding"===e.type)?.options;if(!s?.length){o(2,`skipping ${e.dir} because no compression is configured`);continue}o(2,`compressing files in ${e.dir} using ${s.map(e=>e.match).join(", ")}`);const i=await w(e.dir,s,t),n=R(i.filter(({mime:e})=>e.startsWith("text/"))),a=R(i.filter(({mime:e})=>!e.startsWith("text/")));o(2,`text: ${B(n.rawSize)} / ${B(n.bestSize)} compressed`),o(2,`other: ${B(a.rawSize)} / ${B(a.bestSize)} compressed`),r+=n.created+a.created}o(2,`${((e,t,o=t+"s")=>1===e?`1 ${t}`:`${e} ${o}`)(r,"compressed file")} written`)})(t.servers,t.minCompress,W),t.noServe?i():r.set(t.servers)}function a(){return W(2,"refreshing config"),n()}n(),process.on("SIGHUP",()=>a()),process.stdin.on("data",e=>{e.includes("\n")&&a()}),process.on("SIGINT",()=>{W(2,""),i()})})();
|
package/schema.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"$schema":"https://json-schema.org/draft-07/schema#","title":"Configuration for running one or more servers via the web-listener CLI","type":"object","additionalProperties":false,"required":["servers"],"properties":{"$schema":{"type":"string"},"servers":{"type":"array","items":{"$ref":"#/$defs/server"}},"mime":{"anyOf":[{"type":"array","items":{"$ref":"#/$defs/mime"}},{"$ref":"#/$defs/mime"}],"default":[]},"writeCompressed":{"title":"Generate and save zstd, brotli, gzip, or deflate files for each served file before starting","type":"boolean","default":false},"minCompress":{"title":"The minimum number of bytes that compression must save, otherwise the file is not written","type":"integer","default":300},"noServe":{"title":"Stop after validating the configuration and optionally writing any compressed files","type":"boolean","default":false},"log":{"title":"Set the logging level. \"ready\" prints only the \"all servers ready\" line, \"progress\" prints server startup and shutdown progress.","enum":["none","ready","progress"],"default":"progress"}},"$defs":{"server":{"title":"Configuration for one server","type":"object","additionalProperties":false,"defaultSnippets":[{"label":"server","description":"Defines a server on a given port","body":{"port":"^${1:80}","mount":[]}}],"required":["port","mount"],"properties":{"port":{"type":"integer","minimum":1,"maximum":65535},"host":{"type":"string","default":"localhost"},"options":{"type":"object","default":{},"additionalProperties":false,"properties":{"requestTimeout":{"type":"integer"},"keepAliveTimeout":{"type":"integer"},"keepAliveTimeoutBuffer":{"type":"integer"},"connectionsCheckingInterval":{"type":"integer"},"headersTimeout":{"type":"integer"},"highWaterMark":{"type":"integer"},"maxHeaderSize":{"type":"integer"},"noDelay":{"type":"boolean"},"requireHostHeader":{"type":"boolean"},"keepAlive":{"type":"boolean"},"keepAliveInitialDelay":{"type":"integer"},"uniqueHeaders":{"type":"array","items":{"type":"string"}},"backlog":{"type":"integer","default":511},"socketTimeout":{"type":"integer"},"rejectNonStandardExpect":{"type":"boolean","default":false},"autoContinue":{"type":"boolean","default":false},"logRequests":{"type":"boolean","default":true},"restartTimeout":{"type":"integer","default":2000},"shutdownTimeout":{"type":"integer","default":500}}},"mount":{"type":"array","items":{"title":"Service to mount on the server","defaultSnippets":[{"label":"files","body":{"type":"files","path":"${1:/}","dir":"${2:.}"}},{"label":"proxy","body":{"type":"proxy","path":"${1:/}","target":"${2:http://localhost:8080}"}},{"label":"fixture","body":{"type":"fixture","method":"${1:GET}","path":"${2:/}","status":"^${3:200}","body":"$4"}}],"anyOf":[{"$ref":"#/$defs/mount-files"},{"$ref":"#/$defs/mount-proxy"},{"$ref":"#/$defs/mount-fixture"},{"$ref":"#/$defs/mount-redirect"}]}}}},"mount-files":{"type":"object","additionalProperties":false,"required":["type"],"properties":{"type":{"const":"files"},"path":{"type":"string","default":"/"},"dir":{"type":"string","default":".","format":"uri-reference"},"options":{"type":"object","default":{},"additionalProperties":false,"properties":{"mode":{"enum":["dynamic","static-paths"],"default":"dynamic"},"fallback":{"type":"object","additionalProperties":false,"required":["filePath"],"properties":{"statusCode":{"$ref":"#/$defs/status","default":200},"filePath":{"type":"string"}}},"subDirectories":{"anyOf":[{"type":"boolean"},{"type":"integer"}],"default":true},"caseSensitive":{"enum":["exact","filesystem","force-lowercase"],"default":"exact"},"allowAllDotfiles":{"type":"boolean","default":false},"allowAllTildefiles":{"type":"boolean","default":false},"allowDirectIndexAccess":{"type":"boolean","default":false},"hide":{"type":"array","default":[],"items":{"type":"string"}},"allow":{"type":"array","items":{"type":"string"},"default":[".well-known"]},"indexFiles":{"type":"array","items":{"type":"string"},"default":["index.htm","index.html"]},"implicitSuffixes":{"type":"array","items":{"type":"string"},"default":[]},"negotiation":{"type":"array","default":[],"items":{"type":"object","additionalProperties":false,"properties":{"type":{"enum":["mime","language","encoding"]},"options":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["match","file"],"properties":{"match":{"type":"string"},"file":{"type":"string"}}}}}}}}}}},"mount-proxy":{"type":"object","additionalProperties":false,"required":["type","target"],"properties":{"type":{"const":"proxy"},"path":{"type":"string","default":"/"},"target":{"type":"string"},"options":{"type":"object","default":{},"additionalProperties":false,"properties":{"noDelay":{"type":"boolean"},"keepAlive":{"type":"boolean"},"keepAliveInitialDelay":{"type":"integer"},"keepAliveMsecs":{"type":"integer"},"agentKeepAliveTimeoutBuffer":{"type":"integer"},"maxSockets":{"type":"integer"},"maxFreeSockets":{"type":"integer"},"timeout":{"type":"integer"},"blockRequestHeaders":{"type":"array","items":{"type":"string"}},"blockResponseHeaders":{"type":"array","items":{"type":"string"}},"servername":{"type":"string"},"ca":{"type":"string"},"cert":{"type":"string"},"sigalgs":{"type":"string"},"ciphers":{"type":"string"},"crl":{"type":"string"},"ecdhCurve":{"type":"string"},"key":{"type":"string"},"passphrase":{"type":"string"},"pfx":{"type":"string"},"sessionTimeout":{"type":"integer"},"maxCachedSessions":{"type":"integer"}}}}},"mount-fixture":{"type":"object","additionalProperties":false,"required":["type","path","body"],"properties":{"type":{"const":"fixture"},"path":{"type":"string"},"method":{"type":"string","default":"GET"},"status":{"$ref":"#/$defs/status","default":200},"headers":{"type":"object","default":{},"additionalProperties":{"anyOf":[{"type":"string"},{"type":"number"},{"type":"array","items":{"type":"string"}}]}},"body":{"type":"string"}}},"mount-redirect":{"type":"object","additionalProperties":false,"required":["type","path","target"],"properties":{"type":{"const":"redirect"},"path":{"type":"string"},"status":{"$ref":"#/$defs/status","default":307},"target":{"type":"string"}}},"mime":{"anyOf":[{"type":"string","pattern":"^file://","format":"uri-reference"},{"type":"string","pattern":"^([^=;]+=[^/;]+/[^;]+(;|$))+$"},{"type":"object","additionalProperties":{"type":"string","pattern":"/"}}]},"status":{"type":"integer","minimum":200,"maximum":599}}}
|
|
1
|
+
{"$schema":"https://json-schema.org/draft-07/schema#","title":"Configuration for running one or more servers via the web-listener CLI","type":"object","additionalProperties":false,"required":["servers"],"properties":{"$schema":{"type":"string"},"servers":{"type":"array","items":{"$ref":"#/$defs/server"}},"mime":{"anyOf":[{"type":"array","items":{"$ref":"#/$defs/mime"}},{"$ref":"#/$defs/mime"}],"default":[]},"writeCompressed":{"title":"Generate and save zstd, brotli, gzip, or deflate files for each served file before starting","type":"boolean","default":false},"minCompress":{"title":"The minimum number of bytes that compression must save, otherwise the file is not written","type":"integer","default":300},"noServe":{"title":"Stop after validating the configuration and optionally writing any compressed files","type":"boolean","default":false},"log":{"title":"Set the logging level. \"ready\" prints only the \"all servers ready\" line, \"progress\" prints server startup and shutdown progress.","enum":["none","ready","progress"],"default":"progress"}},"$defs":{"server":{"title":"Configuration for one server","type":"object","additionalProperties":false,"defaultSnippets":[{"label":"server","description":"Defines a server on a given port","body":{"port":"^${1:80}","mount":[]}}],"required":["port","mount"],"properties":{"port":{"type":"integer","minimum":1,"maximum":65535},"host":{"type":"string","default":"localhost"},"options":{"type":"object","default":{},"additionalProperties":false,"properties":{"requestTimeout":{"type":"integer"},"keepAliveTimeout":{"type":"integer"},"keepAliveTimeoutBuffer":{"type":"integer"},"connectionsCheckingInterval":{"type":"integer"},"headersTimeout":{"type":"integer"},"highWaterMark":{"type":"integer"},"maxHeaderSize":{"type":"integer"},"noDelay":{"type":"boolean"},"requireHostHeader":{"type":"boolean"},"keepAlive":{"type":"boolean"},"keepAliveInitialDelay":{"type":"integer"},"uniqueHeaders":{"type":"array","items":{"type":"string"}},"backlog":{"type":"integer","default":511},"socketTimeout":{"type":"integer"},"rejectNonStandardExpect":{"type":"boolean","default":false},"autoContinue":{"type":"boolean","default":false},"logRequests":{"type":"boolean","default":true},"restartTimeout":{"type":"integer","default":2000},"shutdownTimeout":{"type":"integer","default":500}}},"mount":{"type":"array","items":{"title":"Service to mount on the server","defaultSnippets":[{"label":"files","body":{"type":"files","path":"${1:/}","dir":"${2:.}"}},{"label":"proxy","body":{"type":"proxy","path":"${1:/}","target":"${2:http://localhost:8080}"}},{"label":"fixture","body":{"type":"fixture","method":"${1:GET}","path":"${2:/}","status":"^${3:200}","body":"$4"}}],"anyOf":[{"$ref":"#/$defs/mount-files"},{"$ref":"#/$defs/mount-proxy"},{"$ref":"#/$defs/mount-fixture"},{"$ref":"#/$defs/mount-redirect"}]}}}},"mount-files":{"type":"object","additionalProperties":false,"required":["type"],"properties":{"type":{"const":"files"},"path":{"type":"string","default":"/"},"dir":{"type":"string","default":".","format":"uri-reference"},"options":{"type":"object","default":{},"additionalProperties":false,"properties":{"mode":{"enum":["dynamic","static-paths"],"default":"dynamic"},"fallback":{"type":"object","additionalProperties":false,"required":["filePath"],"properties":{"statusCode":{"$ref":"#/$defs/status","default":200},"filePath":{"type":"string"}}},"verbose":{"type":"boolean","default":false},"subDirectories":{"anyOf":[{"type":"boolean"},{"type":"integer"}],"default":true},"caseSensitive":{"enum":["exact","filesystem","force-lowercase"],"default":"exact"},"allowAllDotfiles":{"type":"boolean","default":false},"allowAllTildefiles":{"type":"boolean","default":false},"allowDirectIndexAccess":{"type":"boolean","default":false},"hide":{"type":"array","default":[],"items":{"type":"string"}},"allow":{"type":"array","items":{"type":"string"},"default":[".well-known"]},"indexFiles":{"type":"array","items":{"type":"string"},"default":["index.htm","index.html"]},"implicitSuffixes":{"type":"array","items":{"type":"string"},"default":[]},"negotiation":{"type":"array","default":[],"items":{"type":"object","additionalProperties":false,"properties":{"type":{"enum":["mime","language","encoding"]},"options":{"type":"array","items":{"type":"object","additionalProperties":false,"required":["match","file"],"properties":{"match":{"type":"string"},"file":{"type":"string"}}}}}}}}}}},"mount-proxy":{"type":"object","additionalProperties":false,"required":["type","target"],"properties":{"type":{"const":"proxy"},"path":{"type":"string","default":"/"},"target":{"type":"string"},"options":{"type":"object","default":{},"additionalProperties":false,"properties":{"noDelay":{"type":"boolean"},"keepAlive":{"type":"boolean"},"keepAliveInitialDelay":{"type":"integer"},"keepAliveMsecs":{"type":"integer"},"agentKeepAliveTimeoutBuffer":{"type":"integer"},"maxSockets":{"type":"integer"},"maxFreeSockets":{"type":"integer"},"timeout":{"type":"integer"},"blockRequestHeaders":{"type":"array","items":{"type":"string"}},"blockResponseHeaders":{"type":"array","items":{"type":"string"}},"servername":{"type":"string"},"ca":{"type":"string"},"cert":{"type":"string"},"sigalgs":{"type":"string"},"ciphers":{"type":"string"},"crl":{"type":"string"},"ecdhCurve":{"type":"string"},"key":{"type":"string"},"passphrase":{"type":"string"},"pfx":{"type":"string"},"sessionTimeout":{"type":"integer"},"maxCachedSessions":{"type":"integer"}}}}},"mount-fixture":{"type":"object","additionalProperties":false,"required":["type","path","body"],"properties":{"type":{"const":"fixture"},"path":{"type":"string"},"method":{"type":"string","default":"GET"},"status":{"$ref":"#/$defs/status","default":200},"headers":{"type":"object","default":{},"additionalProperties":{"anyOf":[{"type":"string"},{"type":"number"},{"type":"array","items":{"type":"string"}}]}},"body":{"type":"string"}}},"mount-redirect":{"type":"object","additionalProperties":false,"required":["type","path","target"],"properties":{"type":{"const":"redirect"},"path":{"type":"string"},"status":{"$ref":"#/$defs/status","default":307},"target":{"type":"string"}}},"mime":{"anyOf":[{"type":"string","pattern":"^file://","format":"uri-reference"},{"type":"string","pattern":"^([^=;]+=[^/;]+/[^;]+(;|$))+$"},{"type":"object","additionalProperties":{"type":"string","pattern":"/"}}]},"status":{"type":"integer","minimum":200,"maximum":599}}}
|