@sourceregistry/node-webserver 1.4.0 → 1.6.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/README.md +45 -0
- package/dist/index.cjs.js +2 -2
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +187 -73
- package/dist/index.es.js.map +1 -1
- package/dist/middlewares/ratelimiter/SlidingWindow.d.ts +16 -0
- package/dist/middlewares/ratelimiter/index.d.ts +15 -0
- package/dist/middlewares/requestid/index.d.ts +7 -0
- package/dist/types/server.d.ts +1 -0
- package/package.json +1 -1
package/dist/index.es.js
CHANGED
|
@@ -57,35 +57,123 @@ var E = class {
|
|
|
57
57
|
async resetAll() {
|
|
58
58
|
this.data.clear();
|
|
59
59
|
}
|
|
60
|
-
}, D =
|
|
60
|
+
}, D = class {
|
|
61
|
+
constructor(e) {
|
|
62
|
+
this.data = /* @__PURE__ */ new Map(), this.windowMs = e.windowMs, this.startCleanup();
|
|
63
|
+
}
|
|
64
|
+
async incr(e) {
|
|
65
|
+
let t = Date.now(), n = t - this.windowMs, r = this.data.get(e) || [];
|
|
66
|
+
r = r.filter((e) => e > n), r.push(t), this.data.set(e, r);
|
|
67
|
+
let i = t + this.windowMs;
|
|
68
|
+
return {
|
|
69
|
+
current: r.length,
|
|
70
|
+
reset: i
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
startCleanup() {
|
|
74
|
+
this.cleanupInterval = setInterval(() => {
|
|
75
|
+
let e = Date.now();
|
|
76
|
+
for (let [t, n] of this.data) {
|
|
77
|
+
let r = e - this.windowMs, i = n.filter((e) => e > r);
|
|
78
|
+
i.length === 0 ? this.data.delete(t) : this.data.set(t, i);
|
|
79
|
+
}
|
|
80
|
+
}, Math.min(this.windowMs, 3e5));
|
|
81
|
+
}
|
|
82
|
+
stop() {
|
|
83
|
+
this.cleanupInterval && clearInterval(this.cleanupInterval);
|
|
84
|
+
}
|
|
85
|
+
async resetAll() {
|
|
86
|
+
this.data.clear();
|
|
87
|
+
}
|
|
88
|
+
}, ee = /* @__PURE__ */ S({
|
|
89
|
+
MemoryStore: () => E,
|
|
90
|
+
SlidingWindowStore: () => D,
|
|
91
|
+
fixedWindowLimit: () => te,
|
|
92
|
+
slidingWindowLimit: () => O
|
|
93
|
+
});
|
|
61
94
|
function O(e) {
|
|
95
|
+
let { windowMs: t = 6e4, max: n, key: r = (e) => e.getClientAddress(), message: i = "Too many requests, please try again later.", statusCode: a = 429, headers: o = "include", onRateLimit: s, store: c = new D({ windowMs: t }) } = e;
|
|
96
|
+
return async (e, t) => {
|
|
97
|
+
let l = r(e);
|
|
98
|
+
if (typeof l != "string" || !/^[a-zA-Z0-9_.-]+$/.test(l)) throw Error("Invalid rate limit key: only alphanumeric, underscore, dot, and hyphen allowed");
|
|
99
|
+
let u = `rl:${l}`, { current: d, reset: f } = await c.incr(u), p = Math.ceil((f - Date.now()) / 1e3);
|
|
100
|
+
if (d > n) {
|
|
101
|
+
if (s) {
|
|
102
|
+
let t = f - Date.now();
|
|
103
|
+
s(e, {
|
|
104
|
+
current: d,
|
|
105
|
+
max: n,
|
|
106
|
+
key: u,
|
|
107
|
+
reset: Math.floor(f / 1e3),
|
|
108
|
+
remaining: 0,
|
|
109
|
+
resetTimeMs: t
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
let t = {
|
|
113
|
+
status: a,
|
|
114
|
+
headers: new Headers()
|
|
115
|
+
}, r = t.headers;
|
|
116
|
+
o === "include" && (r.set("X-RateLimit-Limit", String(n)), r.set("X-RateLimit-Remaining", "0"), r.set("X-RateLimit-Reset", String(Math.floor(f / 1e3))), r.set("Retry-After", String(p)));
|
|
117
|
+
let c;
|
|
118
|
+
return typeof i == "string" ? (c = i, r.set("Content-Type", "text/plain")) : (c = JSON.stringify(i), r.set("Content-Type", "application/json")), new Response(c, t);
|
|
119
|
+
}
|
|
120
|
+
if (e.rateLimit = {
|
|
121
|
+
current: d,
|
|
122
|
+
limit: n,
|
|
123
|
+
reset: new Date(f),
|
|
124
|
+
remaining: n - d
|
|
125
|
+
}, o === "include") {
|
|
126
|
+
let t = {
|
|
127
|
+
"X-RateLimit-Limit": String(n),
|
|
128
|
+
"X-RateLimit-Remaining": String(n - d),
|
|
129
|
+
"X-RateLimit-Reset": String(Math.floor(f / 1e3))
|
|
130
|
+
}, r = e.setHeaders;
|
|
131
|
+
e.setHeaders = (e) => {
|
|
132
|
+
r({
|
|
133
|
+
...t,
|
|
134
|
+
...e
|
|
135
|
+
});
|
|
136
|
+
}, r(t);
|
|
137
|
+
}
|
|
138
|
+
return t();
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
function te(e) {
|
|
62
142
|
let { windowMs: t = 6e4, max: n, key: r = (e) => e.getClientAddress(), message: i = "Too many requests, please try again later.", statusCode: a = 429, headers: o = "include", onRateLimit: s, store: c = new E({ windowMs: t }) } = e;
|
|
63
143
|
return async (e, t) => {
|
|
64
|
-
let l =
|
|
65
|
-
if (
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
144
|
+
let l = r(e);
|
|
145
|
+
if (typeof l != "string" || !/^[a-zA-Z0-9_.-]+$/.test(l)) throw Error("Invalid rate limit key: only alphanumeric, underscore, dot, and hyphen allowed");
|
|
146
|
+
let u = `rl:${l}`, { current: d, reset: f } = await c.incr(u), p = Math.ceil((f - Date.now()) / 1e3);
|
|
147
|
+
if (d > n) {
|
|
148
|
+
if (s) {
|
|
149
|
+
let t = f - Date.now();
|
|
150
|
+
s(e, {
|
|
151
|
+
current: d,
|
|
152
|
+
max: n,
|
|
153
|
+
key: u,
|
|
154
|
+
reset: Math.floor(f / 1e3),
|
|
155
|
+
remaining: 0,
|
|
156
|
+
resetTimeMs: t
|
|
157
|
+
});
|
|
158
|
+
}
|
|
71
159
|
let t = {
|
|
72
160
|
status: a,
|
|
73
161
|
headers: new Headers()
|
|
74
162
|
}, r = t.headers;
|
|
75
|
-
o === "include" && (r.set("X-RateLimit-Limit", String(n)), r.set("X-RateLimit-Remaining", "0"), r.set("X-RateLimit-Reset", String(Math.floor(
|
|
163
|
+
o === "include" && (r.set("X-RateLimit-Limit", String(n)), r.set("X-RateLimit-Remaining", "0"), r.set("X-RateLimit-Reset", String(Math.floor(f / 1e3))), r.set("Retry-After", String(p)));
|
|
76
164
|
let c;
|
|
77
165
|
return typeof i == "string" ? (c = i, r.set("Content-Type", "text/plain")) : (c = JSON.stringify(i), r.set("Content-Type", "application/json")), new Response(c, t);
|
|
78
166
|
}
|
|
79
167
|
if (e.rateLimit = {
|
|
80
|
-
current:
|
|
168
|
+
current: d,
|
|
81
169
|
limit: n,
|
|
82
|
-
reset: new Date(
|
|
83
|
-
remaining: n -
|
|
170
|
+
reset: new Date(f),
|
|
171
|
+
remaining: n - d
|
|
84
172
|
}, o === "include") {
|
|
85
173
|
let t = {
|
|
86
174
|
"X-RateLimit-Limit": String(n),
|
|
87
|
-
"X-RateLimit-Remaining": String(n -
|
|
88
|
-
"X-RateLimit-Reset": String(Math.floor(
|
|
175
|
+
"X-RateLimit-Remaining": String(n - d),
|
|
176
|
+
"X-RateLimit-Reset": String(Math.floor(f / 1e3))
|
|
89
177
|
}, r = e.setHeaders;
|
|
90
178
|
e.setHeaders = (e) => {
|
|
91
179
|
r({
|
|
@@ -99,7 +187,7 @@ function O(e) {
|
|
|
99
187
|
}
|
|
100
188
|
//#endregion
|
|
101
189
|
//#region src/middlewares/cros/index.ts
|
|
102
|
-
var
|
|
190
|
+
var ne = /* @__PURE__ */ S({ policy: () => M }), re = [
|
|
103
191
|
"GET",
|
|
104
192
|
"POST",
|
|
105
193
|
"PUT",
|
|
@@ -107,7 +195,7 @@ var ee = /* @__PURE__ */ S({ policy: () => M }), te = [
|
|
|
107
195
|
"PATCH",
|
|
108
196
|
"HEAD",
|
|
109
197
|
"OPTIONS"
|
|
110
|
-
],
|
|
198
|
+
], ie = [
|
|
111
199
|
"Accept",
|
|
112
200
|
"Accept-Language",
|
|
113
201
|
"Content-Language",
|
|
@@ -131,7 +219,7 @@ function j(e, t) {
|
|
|
131
219
|
return e ? n === "*" ? t.credentials ? e : "*" : A(e, n) ? e : null : n === "*" ? "*" : null;
|
|
132
220
|
}
|
|
133
221
|
function M(e = {}) {
|
|
134
|
-
let { methods: t =
|
|
222
|
+
let { methods: t = re, allowedHeaders: n = k, exposedHeaders: r, credentials: i = !1, maxAge: a = 86400, onResponse: o } = e, s = t.join(","), c = [...ie, ...n].join(","), l = [
|
|
135
223
|
["Vary", "Origin,Access-Control-Request-Method,Access-Control-Request-Headers"],
|
|
136
224
|
["Access-Control-Allow-Methods", s],
|
|
137
225
|
["Access-Control-Allow-Headers", c]
|
|
@@ -192,25 +280,35 @@ function I(e, t, n) {
|
|
|
192
280
|
//#region src/middlewares/requestid/index.ts
|
|
193
281
|
var L = /* @__PURE__ */ S({ assign: () => R });
|
|
194
282
|
function R(t = {}) {
|
|
195
|
-
let n = t.headerName?.toLowerCase() ?? "x-request-id", r = t.generate ?? e;
|
|
283
|
+
let n = t.headerName?.toLowerCase() ?? "x-request-id", r = t.generate ?? e, i = t.clientRequestId ?? !1;
|
|
196
284
|
return async (e, t) => {
|
|
197
|
-
let
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
285
|
+
let a = e.request.headers.get(n) ?? r();
|
|
286
|
+
if (i) {
|
|
287
|
+
let t = e.request.headers.get("x-client-request-id");
|
|
288
|
+
if (t !== null) {
|
|
289
|
+
if (!z(t) || t.length > 512) return new Response("Invalid X-Client-Request-Id header", { status: 400 });
|
|
290
|
+
a = t;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
Object.assign(e.locals, { requestId: a });
|
|
294
|
+
let o = await t();
|
|
295
|
+
if (!o) return;
|
|
296
|
+
if (o.headers.has(n)) return o;
|
|
297
|
+
let s = new Headers(o.headers);
|
|
298
|
+
return s.set(n, a), new Response(o.body, {
|
|
299
|
+
status: o.status,
|
|
300
|
+
statusText: o.statusText,
|
|
301
|
+
headers: s
|
|
207
302
|
});
|
|
208
303
|
};
|
|
209
304
|
}
|
|
305
|
+
function z(e) {
|
|
306
|
+
return /^[\x00-\x7F]*$/.test(e);
|
|
307
|
+
}
|
|
210
308
|
//#endregion
|
|
211
309
|
//#region src/middlewares/timeout/index.ts
|
|
212
|
-
var
|
|
213
|
-
function
|
|
310
|
+
var B = /* @__PURE__ */ S({ deadline: () => V });
|
|
311
|
+
function V(e) {
|
|
214
312
|
let { ms: t, status: n = 504, body: r = "Gateway Timeout", onTimeout: i } = e;
|
|
215
313
|
if (!Number.isFinite(t) || t <= 0) throw TypeError("Timeout.deadline requires a positive ms value");
|
|
216
314
|
return async (e, a) => {
|
|
@@ -235,7 +333,7 @@ function B(e) {
|
|
|
235
333
|
}
|
|
236
334
|
//#endregion
|
|
237
335
|
//#region src/types/RequestMethod.ts
|
|
238
|
-
var
|
|
336
|
+
var H = [
|
|
239
337
|
"GET",
|
|
240
338
|
"PUT",
|
|
241
339
|
"POST",
|
|
@@ -243,7 +341,7 @@ var V = [
|
|
|
243
341
|
"PATCH",
|
|
244
342
|
"HEAD",
|
|
245
343
|
"OPTIONS"
|
|
246
|
-
],
|
|
344
|
+
], U = class {
|
|
247
345
|
static {
|
|
248
346
|
this.cache = /* @__PURE__ */ new Map();
|
|
249
347
|
}
|
|
@@ -253,7 +351,7 @@ var V = [
|
|
|
253
351
|
static set(e, t) {
|
|
254
352
|
this.cache.set(e, t);
|
|
255
353
|
}
|
|
256
|
-
},
|
|
354
|
+
}, W = class {
|
|
257
355
|
constructor() {
|
|
258
356
|
this._routes = [], this._wsRoutes = [], this._nestedRouters = [], this._middlewares = [], this._preHandlers = [], this._postHandlers = [], this.routesSorted = !1, this.wsRoutesSorted = !1;
|
|
259
357
|
}
|
|
@@ -285,7 +383,7 @@ var V = [
|
|
|
285
383
|
return this.addHandler("OPTIONS", e, t, n);
|
|
286
384
|
}
|
|
287
385
|
USE(e, t, ...n) {
|
|
288
|
-
return
|
|
386
|
+
return H.forEach((r) => this.addHandler(r, e, t, n)), this;
|
|
289
387
|
}
|
|
290
388
|
action(e, t, ...n) {
|
|
291
389
|
return this.addHandler("POST", e, async (e) => {
|
|
@@ -441,7 +539,7 @@ var V = [
|
|
|
441
539
|
}), this.routesSorted = !1, this;
|
|
442
540
|
}
|
|
443
541
|
createPathRegex(e) {
|
|
444
|
-
let t =
|
|
542
|
+
let t = U.get(e);
|
|
445
543
|
if (t) return t;
|
|
446
544
|
let n = [], r = !1, i, a = e.split("/").filter(Boolean);
|
|
447
545
|
i = a.reduce((e, t) => t.startsWith("[...") ? e - 10 : t.startsWith("[[") ? e - 5 : t.startsWith("[") ? e - 1 : e + 1, 0);
|
|
@@ -464,7 +562,7 @@ var V = [
|
|
|
464
562
|
isCatchAll: r,
|
|
465
563
|
priority: i
|
|
466
564
|
};
|
|
467
|
-
return
|
|
565
|
+
return U.set(e, s), s;
|
|
468
566
|
}
|
|
469
567
|
createPrefixRegex(e) {
|
|
470
568
|
let t = [], n = !1, r, i = e.split("/").filter(Boolean);
|
|
@@ -557,17 +655,17 @@ var V = [
|
|
|
557
655
|
this._wsRoutes.sort((e, t) => t.priority - e.priority), this.wsRoutesSorted = !0;
|
|
558
656
|
}
|
|
559
657
|
formatActionResult(e) {
|
|
560
|
-
return e instanceof Response ? e : e?.type === "failure" && "status" in e ?
|
|
658
|
+
return e instanceof Response ? e : e?.type === "failure" && "status" in e ? G.fail(e.status, e.data) : G.success(200, e ?? void 0);
|
|
561
659
|
}
|
|
562
660
|
handleActionError(e) {
|
|
563
|
-
if (C(e)) return
|
|
661
|
+
if (C(e)) return G.error(e.status, { message: e.statusText || "Error" });
|
|
564
662
|
if (w(e)) {
|
|
565
663
|
let t = e.headers.get("Location") || "/";
|
|
566
|
-
return
|
|
664
|
+
return G.redirect(e.status, t);
|
|
567
665
|
}
|
|
568
|
-
return console.error(e),
|
|
666
|
+
return console.error(e), G.error(500, { message: "Internal Server Error" });
|
|
569
667
|
}
|
|
570
|
-
},
|
|
668
|
+
}, G = {
|
|
571
669
|
success: (e = 200, t) => new Response(JSON.stringify({
|
|
572
670
|
data: t,
|
|
573
671
|
type: "success",
|
|
@@ -600,7 +698,7 @@ var V = [
|
|
|
600
698
|
status: e,
|
|
601
699
|
headers: { "Content-Type": "application/json" }
|
|
602
700
|
})
|
|
603
|
-
},
|
|
701
|
+
}, K = class {
|
|
604
702
|
constructor(e, t) {
|
|
605
703
|
this.raw = e.headers.get("cookie") ?? "", this.setCookieHeader = t;
|
|
606
704
|
}
|
|
@@ -622,11 +720,11 @@ var V = [
|
|
|
622
720
|
maxAge: 0
|
|
623
721
|
});
|
|
624
722
|
}
|
|
625
|
-
},
|
|
723
|
+
}, q = class extends Error {
|
|
626
724
|
constructor(e = "Payload Too Large") {
|
|
627
725
|
super(e), this.status = 413, this.name = "PayloadTooLargeError";
|
|
628
726
|
}
|
|
629
|
-
},
|
|
727
|
+
}, J = class extends W {
|
|
630
728
|
constructor(e) {
|
|
631
729
|
super(), this.upgradeHandlerInstalled = !1, this.config = e ?? {
|
|
632
730
|
type: "http",
|
|
@@ -736,7 +834,7 @@ var V = [
|
|
|
736
834
|
if (!t) return e;
|
|
737
835
|
let n = 0, r = new a({ transform(e, r, i) {
|
|
738
836
|
if (n += Buffer.byteLength(e), n > t) {
|
|
739
|
-
i(new
|
|
837
|
+
i(new q());
|
|
740
838
|
return;
|
|
741
839
|
}
|
|
742
840
|
i(null, e);
|
|
@@ -762,7 +860,7 @@ var V = [
|
|
|
762
860
|
if (!this.isTrustedProxy(t)) return this.normalizeAddress(t);
|
|
763
861
|
let n = e.headers["x-forwarded-for"];
|
|
764
862
|
if (!n) return this.normalizeAddress(t);
|
|
765
|
-
let r = this.parseForwardedHeader(n);
|
|
863
|
+
let r = this.parseForwardedHeader(n).filter((e) => this.isValidIP(e));
|
|
766
864
|
r.push(t);
|
|
767
865
|
for (let e = r.length - 1; e >= 0; --e) {
|
|
768
866
|
let t = r[e];
|
|
@@ -806,6 +904,19 @@ var V = [
|
|
|
806
904
|
normalizeAddress(e) {
|
|
807
905
|
return e.startsWith("::ffff:") ? e.slice(7) : e;
|
|
808
906
|
}
|
|
907
|
+
isValidIP(e) {
|
|
908
|
+
if (e.includes(":")) {
|
|
909
|
+
if (e.includes(":::")) return !1;
|
|
910
|
+
let t = e.split(":");
|
|
911
|
+
return t.length <= 8 && t.every((e) => e === "" || /^[0-9a-fA-F]+$/.test(e));
|
|
912
|
+
}
|
|
913
|
+
let t = e.split(".");
|
|
914
|
+
return t.length === 4 && t.every((e) => {
|
|
915
|
+
if (e === "" || e.length > 3) return !1;
|
|
916
|
+
let t = parseInt(e, 10);
|
|
917
|
+
return !isNaN(t) && t >= 0 && t <= 255 && e === String(t);
|
|
918
|
+
});
|
|
919
|
+
}
|
|
809
920
|
parseForwardedHeader(e) {
|
|
810
921
|
return (Array.isArray(e) ? e.join(",") : e).split(",").map((e) => this.normalizeAddress(e.trim())).filter(Boolean);
|
|
811
922
|
}
|
|
@@ -830,7 +941,7 @@ var V = [
|
|
|
830
941
|
return Number.isFinite(r) && r <= t;
|
|
831
942
|
}
|
|
832
943
|
handleError(e) {
|
|
833
|
-
if (e instanceof
|
|
944
|
+
if (e instanceof q) return new Response(e.message, { status: e.status });
|
|
834
945
|
if (C(e)) return new Response(JSON.stringify({
|
|
835
946
|
error: e.statusText || "Error",
|
|
836
947
|
status: e.status
|
|
@@ -928,7 +1039,7 @@ var V = [
|
|
|
928
1039
|
r && t.set(n, r);
|
|
929
1040
|
}
|
|
930
1041
|
toRequestEvent(e, t, n) {
|
|
931
|
-
let r = new
|
|
1042
|
+
let r = new K(e, n.pushSetCookie), i = this.config, a = {}, o = {
|
|
932
1043
|
name: "node-webserver",
|
|
933
1044
|
dev: this.isDevelopment()
|
|
934
1045
|
}, s = /* @__PURE__ */ new Set(), c = {
|
|
@@ -956,7 +1067,7 @@ var V = [
|
|
|
956
1067
|
}, l = this.createEventFetch(c, n);
|
|
957
1068
|
return i.locals && Object.assign(a, i.locals(c)), i.platform && Object.assign(o, i.platform(c)), c;
|
|
958
1069
|
}
|
|
959
|
-
},
|
|
1070
|
+
}, Y = {
|
|
960
1071
|
".avif": "image/avif",
|
|
961
1072
|
".css": "text/css; charset=utf-8",
|
|
962
1073
|
".gif": "image/gif",
|
|
@@ -974,24 +1085,24 @@ var V = [
|
|
|
974
1085
|
".wasm": "application/wasm",
|
|
975
1086
|
".webp": "image/webp",
|
|
976
1087
|
".xml": "application/xml; charset=utf-8"
|
|
977
|
-
},
|
|
1088
|
+
}, ae = {
|
|
978
1089
|
index: "index.html",
|
|
979
1090
|
cacheControl: "public, max-age=0",
|
|
980
1091
|
dotFiles: "ignore"
|
|
981
1092
|
};
|
|
982
|
-
async function
|
|
983
|
-
let r =
|
|
984
|
-
...
|
|
1093
|
+
async function X(e, t, n = {}) {
|
|
1094
|
+
let r = ue(t), i = {
|
|
1095
|
+
...ae,
|
|
985
1096
|
...n
|
|
986
|
-
}, a = await
|
|
1097
|
+
}, a = await oe(e), o = se(r, i.dotFiles);
|
|
987
1098
|
if (o instanceof Response) return o;
|
|
988
1099
|
let s = v(a, o.length > 0 ? o.join(y) : "");
|
|
989
1100
|
if (!Q(a, s)) return new Response("Forbidden", { status: 403 });
|
|
990
|
-
let c = await
|
|
1101
|
+
let c = await ce(s, a, i.index);
|
|
991
1102
|
if (c instanceof Response) return c;
|
|
992
1103
|
let l = await m(c), u = new Headers({
|
|
993
1104
|
"content-length": String(l.size),
|
|
994
|
-
"content-type":
|
|
1105
|
+
"content-type": le(c),
|
|
995
1106
|
"cache-control": i.cacheControl,
|
|
996
1107
|
"last-modified": l.mtime.toUTCString(),
|
|
997
1108
|
"x-content-type-options": "nosniff"
|
|
@@ -1007,10 +1118,10 @@ async function Y(e, t, n = {}) {
|
|
|
1007
1118
|
headers: u
|
|
1008
1119
|
});
|
|
1009
1120
|
}
|
|
1010
|
-
async function
|
|
1121
|
+
async function oe(e) {
|
|
1011
1122
|
return p(e);
|
|
1012
1123
|
}
|
|
1013
|
-
function
|
|
1124
|
+
function se(e, t) {
|
|
1014
1125
|
if (e.includes("\0")) return new Response("Bad Request", { status: 400 });
|
|
1015
1126
|
let n = e.replace(/\\/g, "/").split("/").filter(Boolean), r = [];
|
|
1016
1127
|
for (let e of n) {
|
|
@@ -1031,7 +1142,7 @@ function ie(e, t) {
|
|
|
1031
1142
|
}
|
|
1032
1143
|
return r;
|
|
1033
1144
|
}
|
|
1034
|
-
async function
|
|
1145
|
+
async function ce(e, t, n) {
|
|
1035
1146
|
try {
|
|
1036
1147
|
return (await f(e)).isDirectory() ? Z(v(e, n), t) : Z(e, t);
|
|
1037
1148
|
} catch {
|
|
@@ -1050,13 +1161,13 @@ function Q(e, t) {
|
|
|
1050
1161
|
let n = _(e, t);
|
|
1051
1162
|
return n === "" || !n.startsWith("..") && !g(n);
|
|
1052
1163
|
}
|
|
1053
|
-
function
|
|
1054
|
-
return
|
|
1164
|
+
function le(e) {
|
|
1165
|
+
return Y[h(e).toLowerCase()] ?? "application/octet-stream";
|
|
1055
1166
|
}
|
|
1056
|
-
function
|
|
1167
|
+
function ue(e) {
|
|
1057
1168
|
return typeof e.params.path == "string" ? e.params.path : e.url.pathname.replace(/^\/+/, "");
|
|
1058
1169
|
}
|
|
1059
|
-
var
|
|
1170
|
+
var de = (e, t = {}) => (n) => X(e, n, t), fe = (e, ...t) => async (n) => {
|
|
1060
1171
|
let r = {};
|
|
1061
1172
|
for (let e of t) {
|
|
1062
1173
|
let t = await e(n);
|
|
@@ -1067,16 +1178,19 @@ var se = (e, t = {}) => (n) => Y(e, n, t), ce = (e, ...t) => async (n) => {
|
|
|
1067
1178
|
};
|
|
1068
1179
|
//#endregion
|
|
1069
1180
|
//#region src/helpers/sse.ts
|
|
1070
|
-
function
|
|
1181
|
+
function pe(e, t = {}) {
|
|
1071
1182
|
let n = [];
|
|
1072
|
-
if (t.comment)
|
|
1183
|
+
if (t.comment) {
|
|
1184
|
+
let e = t.comment.replace(/\r\n/g, " ").replace(/\r/g, " ").replace(/\n/g, " ");
|
|
1185
|
+
n.push(`: ${e}`);
|
|
1186
|
+
}
|
|
1073
1187
|
if (t.event && n.push(`event: ${t.event}`), t.id && n.push(`id: ${t.id}`), t.retry !== void 0 && n.push(`retry: ${t.retry}`), e !== void 0) {
|
|
1074
1188
|
let t = typeof e == "string" ? e : JSON.stringify(e);
|
|
1075
1189
|
for (let e of t.split(/\r?\n/)) n.push(`data: ${e}`);
|
|
1076
1190
|
}
|
|
1077
1191
|
return `${n.join("\n")}\n\n`;
|
|
1078
1192
|
}
|
|
1079
|
-
var
|
|
1193
|
+
var $ = (e, t = {}) => (n) => {
|
|
1080
1194
|
let r = new TextEncoder(), i = null, a = !1, o, s = async () => {
|
|
1081
1195
|
if (!a) {
|
|
1082
1196
|
a = !0;
|
|
@@ -1092,7 +1206,7 @@ var ue = (e, t = {}) => (n) => {
|
|
|
1092
1206
|
async start(t) {
|
|
1093
1207
|
i = t;
|
|
1094
1208
|
let c = (e, n = {}) => {
|
|
1095
|
-
a || t.enqueue(r.encode(
|
|
1209
|
+
a || t.enqueue(r.encode(pe(e, n)));
|
|
1096
1210
|
};
|
|
1097
1211
|
n.request.signal.addEventListener("abort", () => {
|
|
1098
1212
|
s();
|
|
@@ -1120,7 +1234,7 @@ var ue = (e, t = {}) => (n) => {
|
|
|
1120
1234
|
...t.headers
|
|
1121
1235
|
}
|
|
1122
1236
|
});
|
|
1123
|
-
},
|
|
1237
|
+
}, me = async (e, t) => {
|
|
1124
1238
|
let n = JSON.stringify(await e);
|
|
1125
1239
|
return new Response(n, {
|
|
1126
1240
|
...t,
|
|
@@ -1131,19 +1245,19 @@ var ue = (e, t = {}) => (n) => {
|
|
|
1131
1245
|
}
|
|
1132
1246
|
});
|
|
1133
1247
|
};
|
|
1134
|
-
function
|
|
1248
|
+
function he(e, t) {
|
|
1135
1249
|
throw new Response(null, {
|
|
1136
1250
|
status: e,
|
|
1137
1251
|
headers: { location: t.toString() }
|
|
1138
1252
|
});
|
|
1139
1253
|
}
|
|
1140
|
-
function
|
|
1254
|
+
function ge(e, t) {
|
|
1141
1255
|
throw new Response(JSON.stringify(typeof t == "string" ? { message: t } : t), {
|
|
1142
1256
|
status: e,
|
|
1143
1257
|
headers: { "content-type": "application/json" }
|
|
1144
1258
|
});
|
|
1145
1259
|
}
|
|
1146
|
-
var
|
|
1260
|
+
var _e = async (e, t) => {
|
|
1147
1261
|
let n = await e;
|
|
1148
1262
|
return new Response(n, {
|
|
1149
1263
|
...t,
|
|
@@ -1153,7 +1267,7 @@ var me = async (e, t) => {
|
|
|
1153
1267
|
...t?.headers
|
|
1154
1268
|
}
|
|
1155
1269
|
});
|
|
1156
|
-
},
|
|
1270
|
+
}, ve = async (e, t) => {
|
|
1157
1271
|
let n = await e;
|
|
1158
1272
|
return new Response(n, {
|
|
1159
1273
|
...t,
|
|
@@ -1165,6 +1279,6 @@ var me = async (e, t) => {
|
|
|
1165
1279
|
});
|
|
1166
1280
|
};
|
|
1167
1281
|
//#endregion
|
|
1168
|
-
export {
|
|
1282
|
+
export { G as Action, ne as CORS, ee as RateLimiter, L as RequestId, H as RequestMethods, W as Router, N as Security, B as Timeout, J as WebServer, de as dir, fe as enhance, ge as error, ve as html, C as isHttpError, w as isRedirect, T as isResponse, me as json, he as redirect, X as serveStatic, $ as sse, _e as text };
|
|
1169
1283
|
|
|
1170
1284
|
//# sourceMappingURL=index.es.js.map
|