@sourceregistry/node-webserver 1.0.0 → 1.2.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 +31 -29
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.es.js +146 -121
- package/dist/index.es.js.map +1 -1
- package/dist/types/router.d.ts +2 -2
- package/dist/types/server.d.ts +5 -6
- package/dist/utils.d.ts +1 -0
- package/examples/simple.ts +2 -2
- package/package.json +1 -1
package/dist/index.es.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { createReadStream as
|
|
2
|
-
import { stat as
|
|
3
|
-
import { sep as
|
|
4
|
-
import { Readable as
|
|
5
|
-
import { createServer as
|
|
6
|
-
import { createServer as
|
|
7
|
-
import { TLSSocket as
|
|
8
|
-
import { Readable as
|
|
9
|
-
import { WebSocketServer as
|
|
10
|
-
import { parse as
|
|
11
|
-
const
|
|
1
|
+
import { createReadStream as I } from "node:fs";
|
|
2
|
+
import { stat as L, realpath as O, lstat as D } from "node:fs/promises";
|
|
3
|
+
import { sep as $, resolve as v, relative as U, isAbsolute as F, extname as z } from "node:path";
|
|
4
|
+
import { Readable as B } from "node:stream";
|
|
5
|
+
import { createServer as q } from "http";
|
|
6
|
+
import { createServer as X } from "https";
|
|
7
|
+
import { TLSSocket as G } from "tls";
|
|
8
|
+
import { Readable as J, Transform as V, Writable as K } from "stream";
|
|
9
|
+
import { WebSocketServer as Y, WebSocket as E } from "ws";
|
|
10
|
+
import { parse as T, serialize as Q } from "cookie";
|
|
11
|
+
const Z = {
|
|
12
12
|
".avif": "image/avif",
|
|
13
13
|
".css": "text/css; charset=utf-8",
|
|
14
14
|
".gif": "image/gif",
|
|
@@ -26,27 +26,27 @@ const Q = {
|
|
|
26
26
|
".wasm": "application/wasm",
|
|
27
27
|
".webp": "image/webp",
|
|
28
28
|
".xml": "application/xml; charset=utf-8"
|
|
29
|
-
},
|
|
29
|
+
}, ee = {
|
|
30
30
|
index: "index.html",
|
|
31
31
|
cacheControl: "public, max-age=0",
|
|
32
32
|
dotFiles: "ignore"
|
|
33
33
|
};
|
|
34
|
-
async function
|
|
35
|
-
const s =
|
|
36
|
-
...
|
|
34
|
+
async function te(a, e, t = {}) {
|
|
35
|
+
const s = ae(e), r = {
|
|
36
|
+
...ee,
|
|
37
37
|
...t
|
|
38
|
-
}, n = await
|
|
38
|
+
}, n = await se(a), o = re(s, r.dotFiles);
|
|
39
39
|
if (o instanceof Response)
|
|
40
40
|
return o;
|
|
41
|
-
const i = o.length > 0 ? o.join(
|
|
42
|
-
if (!
|
|
41
|
+
const i = o.length > 0 ? o.join($) : "", u = v(n, i);
|
|
42
|
+
if (!_(n, u))
|
|
43
43
|
return new Response("Forbidden", { status: 403 });
|
|
44
|
-
const c = await
|
|
44
|
+
const c = await ne(u, n, r.index);
|
|
45
45
|
if (c instanceof Response)
|
|
46
46
|
return c;
|
|
47
|
-
const l = await
|
|
47
|
+
const l = await L(c), d = new Headers({
|
|
48
48
|
"content-length": String(l.size),
|
|
49
|
-
"content-type":
|
|
49
|
+
"content-type": oe(c),
|
|
50
50
|
"cache-control": r.cacheControl,
|
|
51
51
|
"last-modified": l.mtime.toUTCString(),
|
|
52
52
|
"x-content-type-options": "nosniff"
|
|
@@ -57,15 +57,15 @@ async function ee(a, e, t = {}) {
|
|
|
57
57
|
d.set(y, f);
|
|
58
58
|
});
|
|
59
59
|
}
|
|
60
|
-
return new Response(
|
|
60
|
+
return new Response(B.toWeb(I(c)), {
|
|
61
61
|
status: 200,
|
|
62
62
|
headers: d
|
|
63
63
|
});
|
|
64
64
|
}
|
|
65
|
-
async function
|
|
66
|
-
return
|
|
65
|
+
async function se(a) {
|
|
66
|
+
return O(a);
|
|
67
67
|
}
|
|
68
|
-
function
|
|
68
|
+
function re(a, e) {
|
|
69
69
|
if (a.includes("\0"))
|
|
70
70
|
return new Response("Bad Request", { status: 400 });
|
|
71
71
|
const t = a.replace(/\\/g, "/").split("/").filter(Boolean), s = [];
|
|
@@ -90,42 +90,45 @@ function se(a, e) {
|
|
|
90
90
|
}
|
|
91
91
|
return s;
|
|
92
92
|
}
|
|
93
|
-
async function
|
|
93
|
+
async function ne(a, e, t) {
|
|
94
94
|
try {
|
|
95
|
-
if ((await
|
|
96
|
-
const r =
|
|
97
|
-
return
|
|
95
|
+
if ((await D(a)).isDirectory()) {
|
|
96
|
+
const r = v(a, t);
|
|
97
|
+
return C(r, e);
|
|
98
98
|
}
|
|
99
|
-
return
|
|
99
|
+
return C(a, e);
|
|
100
100
|
} catch {
|
|
101
101
|
return new Response("Not Found", { status: 404 });
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
|
-
async function
|
|
104
|
+
async function C(a, e) {
|
|
105
105
|
try {
|
|
106
|
-
const t = await
|
|
107
|
-
return
|
|
106
|
+
const t = await O(a);
|
|
107
|
+
return _(e, t) ? (await L(t)).isFile() ? t : new Response("Not Found", { status: 404 }) : new Response("Forbidden", { status: 403 });
|
|
108
108
|
} catch {
|
|
109
109
|
return new Response("Not Found", { status: 404 });
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
|
-
function
|
|
113
|
-
const t =
|
|
114
|
-
return t === "" || !t.startsWith("..") && !
|
|
115
|
-
}
|
|
116
|
-
function ne(a) {
|
|
117
|
-
return Q[F(a).toLowerCase()] ?? "application/octet-stream";
|
|
112
|
+
function _(a, e) {
|
|
113
|
+
const t = U(a, e);
|
|
114
|
+
return t === "" || !t.startsWith("..") && !F(t);
|
|
118
115
|
}
|
|
119
116
|
function oe(a) {
|
|
120
|
-
return
|
|
117
|
+
return Z[z(a).toLowerCase()] ?? "application/octet-stream";
|
|
121
118
|
}
|
|
122
|
-
function
|
|
123
|
-
return a
|
|
119
|
+
function ae(a) {
|
|
120
|
+
return typeof a.params.path == "string" ? a.params.path : a.url.pathname.replace(/^\/+/, "");
|
|
124
121
|
}
|
|
125
122
|
function N(a) {
|
|
126
|
-
return a
|
|
123
|
+
return x(a) && a.status >= 400 && a.status < 600;
|
|
124
|
+
}
|
|
125
|
+
function j(a) {
|
|
126
|
+
return x(a) && a.status >= 300 && a.status < 400;
|
|
127
127
|
}
|
|
128
|
-
|
|
128
|
+
function x(a) {
|
|
129
|
+
return a instanceof Response;
|
|
130
|
+
}
|
|
131
|
+
class ie {
|
|
129
132
|
constructor(e) {
|
|
130
133
|
this.data = /* @__PURE__ */ new Map(), this.windowMs = e.windowMs, this.startCleanup();
|
|
131
134
|
}
|
|
@@ -148,7 +151,7 @@ class ae {
|
|
|
148
151
|
this.data.clear();
|
|
149
152
|
}
|
|
150
153
|
}
|
|
151
|
-
function
|
|
154
|
+
function ce(a) {
|
|
152
155
|
const {
|
|
153
156
|
windowMs: e = 6e4,
|
|
154
157
|
max: t,
|
|
@@ -157,7 +160,7 @@ function ie(a) {
|
|
|
157
160
|
statusCode: n = 429,
|
|
158
161
|
headers: o = "include",
|
|
159
162
|
onRateLimit: i,
|
|
160
|
-
store: u = new
|
|
163
|
+
store: u = new ie({ windowMs: e })
|
|
161
164
|
} = a;
|
|
162
165
|
return async (c, l) => {
|
|
163
166
|
const d = `rl:${s(c)}`, { current: h, reset: f } = await u.incr(d), y = Math.ceil((f - Date.now()) / 1e3);
|
|
@@ -192,10 +195,10 @@ function ie(a) {
|
|
|
192
195
|
return l();
|
|
193
196
|
};
|
|
194
197
|
}
|
|
195
|
-
const
|
|
198
|
+
const Te = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
196
199
|
__proto__: null,
|
|
197
|
-
fixedWindowLimit:
|
|
198
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
200
|
+
fixedWindowLimit: ce
|
|
201
|
+
}, Symbol.toStringTag, { value: "Module" })), ue = [
|
|
199
202
|
"GET",
|
|
200
203
|
"POST",
|
|
201
204
|
"PUT",
|
|
@@ -203,13 +206,13 @@ const Ee = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
203
206
|
"PATCH",
|
|
204
207
|
"HEAD",
|
|
205
208
|
"OPTIONS"
|
|
206
|
-
],
|
|
209
|
+
], le = [
|
|
207
210
|
"Accept",
|
|
208
211
|
"Accept-Language",
|
|
209
212
|
"Content-Language",
|
|
210
213
|
"Content-Type",
|
|
211
214
|
"Range"
|
|
212
|
-
],
|
|
215
|
+
], de = [
|
|
213
216
|
"Authorization",
|
|
214
217
|
"X-Auth-Token",
|
|
215
218
|
"X-Requested-With",
|
|
@@ -219,34 +222,34 @@ const Ee = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
219
222
|
"X-Real-IP",
|
|
220
223
|
"X-Custom-Header"
|
|
221
224
|
];
|
|
222
|
-
function
|
|
223
|
-
return !a || !e ? !1 : e === "*" ? !0 : e === "null" ? a === "null" : Array.isArray(e) ? e.some((t) =>
|
|
225
|
+
function M(a, e) {
|
|
226
|
+
return !a || !e ? !1 : e === "*" ? !0 : e === "null" ? a === "null" : Array.isArray(e) ? e.some((t) => M(a, t)) : typeof e == "function" ? e(a) : e instanceof RegExp ? e.test(a) : a === e;
|
|
224
227
|
}
|
|
225
|
-
function
|
|
228
|
+
function he(a, e) {
|
|
226
229
|
const { origin: t = "*" } = e;
|
|
227
|
-
return a ? t === "*" ? e.credentials ? a : "*" :
|
|
230
|
+
return a ? t === "*" ? e.credentials ? a : "*" : M(a, t) ? a : null : t === "*" ? "*" : null;
|
|
228
231
|
}
|
|
229
|
-
function
|
|
232
|
+
function fe(a = {}) {
|
|
230
233
|
const {
|
|
231
|
-
methods: e =
|
|
232
|
-
allowedHeaders: t =
|
|
234
|
+
methods: e = ue,
|
|
235
|
+
allowedHeaders: t = de,
|
|
233
236
|
exposedHeaders: s,
|
|
234
237
|
credentials: r = !1,
|
|
235
238
|
maxAge: n = 86400,
|
|
236
239
|
onResponse: o
|
|
237
|
-
} = a, i = "Origin,Access-Control-Request-Method,Access-Control-Request-Headers", u = e.join(","), c = [...
|
|
240
|
+
} = a, i = "Origin,Access-Control-Request-Method,Access-Control-Request-Headers", u = e.join(","), c = [...le, ...t].join(","), l = [
|
|
238
241
|
["Vary", i],
|
|
239
242
|
["Access-Control-Allow-Methods", u],
|
|
240
243
|
["Access-Control-Allow-Headers", c]
|
|
241
244
|
];
|
|
242
245
|
return s && l.push(["Access-Control-Expose-Headers", s.join(",")]), r && l.push(["Access-Control-Allow-Credentials", "true"]), n && l.push(["Access-Control-Max-Age", n.toString()]), async (d, h) => {
|
|
243
|
-
const f = d.request, y = f.headers.get("Origin"), w = f.method === "OPTIONS" && y !== null && f.headers.has("Access-Control-Request-Method"), p =
|
|
246
|
+
const f = d.request, y = f.headers.get("Origin"), w = f.method === "OPTIONS" && y !== null && f.headers.has("Access-Control-Request-Method"), p = he(y, a);
|
|
244
247
|
if (w) {
|
|
245
248
|
if (!p)
|
|
246
249
|
return new Response(null, { status: 403 });
|
|
247
250
|
const g = new Response(null, { status: 204 });
|
|
248
|
-
for (const [H,
|
|
249
|
-
g.headers.set(H,
|
|
251
|
+
for (const [H, k] of l)
|
|
252
|
+
g.headers.set(H, k);
|
|
250
253
|
return g.headers.set("Access-Control-Allow-Origin", p), g;
|
|
251
254
|
}
|
|
252
255
|
const m = await h();
|
|
@@ -264,10 +267,10 @@ function he(a = {}) {
|
|
|
264
267
|
return A;
|
|
265
268
|
};
|
|
266
269
|
}
|
|
267
|
-
const
|
|
270
|
+
const Ce = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
268
271
|
__proto__: null,
|
|
269
|
-
policy:
|
|
270
|
-
}, Symbol.toStringTag, { value: "Module" })),
|
|
272
|
+
policy: fe
|
|
273
|
+
}, Symbol.toStringTag, { value: "Module" })), pe = ["GET", "PUT", "POST", "DELETE", "PATCH", "HEAD", "OPTIONS"];
|
|
271
274
|
class b {
|
|
272
275
|
static {
|
|
273
276
|
this.cache = /* @__PURE__ */ new Map();
|
|
@@ -279,7 +282,7 @@ class b {
|
|
|
279
282
|
this.cache.set(e, t);
|
|
280
283
|
}
|
|
281
284
|
}
|
|
282
|
-
class
|
|
285
|
+
class P {
|
|
283
286
|
constructor() {
|
|
284
287
|
this._routes = [], this._wsRoutes = [], this._nestedRouters = [], this._middlewares = [], this._preHandlers = [], this._postHandlers = [], this.routesSorted = !1, this.wsRoutesSorted = !1;
|
|
285
288
|
}
|
|
@@ -313,7 +316,7 @@ class x {
|
|
|
313
316
|
}
|
|
314
317
|
// Universal method
|
|
315
318
|
USE(e, t, ...s) {
|
|
316
|
-
return
|
|
319
|
+
return pe.forEach((r) => this.addHandler(r, e, t, s)), this;
|
|
317
320
|
}
|
|
318
321
|
// Action handler (POST only)
|
|
319
322
|
action(e, t, ...s) {
|
|
@@ -432,17 +435,22 @@ class x {
|
|
|
432
435
|
return this.handleAtPath(e, e.url.pathname);
|
|
433
436
|
}
|
|
434
437
|
async handleAtPath(e, t) {
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
const
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
438
|
+
try {
|
|
439
|
+
const s = e.request.method;
|
|
440
|
+
let r = await this.runPreHandlers(e);
|
|
441
|
+
if (!r) {
|
|
442
|
+
const o = async () => {
|
|
443
|
+
const i = await this.handleNestedRouters(e, t);
|
|
444
|
+
return i || (this.routesSorted || this.sortRoutes(), this.handleLocalRoutes(e, s, t));
|
|
445
|
+
};
|
|
446
|
+
r = await this.applyMiddlewaresWithList(e, this._middlewares, o);
|
|
447
|
+
}
|
|
448
|
+
const n = r || new Response("No Content", { status: 204 });
|
|
449
|
+
return await this.runPostHandlers(e, n);
|
|
450
|
+
} catch (s) {
|
|
451
|
+
if (x(s)) return s;
|
|
452
|
+
throw s;
|
|
443
453
|
}
|
|
444
|
-
const n = r || new Response("No Content", { status: 204 });
|
|
445
|
-
return this.runPostHandlers(e, n);
|
|
446
454
|
}
|
|
447
455
|
// Apply middlewares utility
|
|
448
456
|
async applyMiddlewaresWithList(e, t, s) {
|
|
@@ -588,16 +596,16 @@ class x {
|
|
|
588
596
|
return e instanceof Response ? e : e?.type === "failure" && "status" in e ? R.fail(e.status, e.data) : R.success(200, e ?? void 0);
|
|
589
597
|
}
|
|
590
598
|
handleActionError(e) {
|
|
591
|
-
if (
|
|
592
|
-
return R.error(e.status, e);
|
|
593
|
-
if (
|
|
599
|
+
if (N(e))
|
|
600
|
+
return R.error(e.status, { message: e.statusText || "Error" });
|
|
601
|
+
if (j(e)) {
|
|
594
602
|
const t = e.headers.get("Location") || "/";
|
|
595
603
|
return R.redirect(e.status, t);
|
|
596
604
|
}
|
|
597
605
|
return console.error(e), R.error(500, { message: "Internal Server Error" });
|
|
598
606
|
}
|
|
599
607
|
static New() {
|
|
600
|
-
return new
|
|
608
|
+
return new P();
|
|
601
609
|
}
|
|
602
610
|
}
|
|
603
611
|
const R = {
|
|
@@ -618,31 +626,31 @@ const R = {
|
|
|
618
626
|
headers: { "Content-Type": "application/json" }
|
|
619
627
|
})
|
|
620
628
|
};
|
|
621
|
-
class
|
|
629
|
+
class me {
|
|
622
630
|
constructor(e, t) {
|
|
623
631
|
this.raw = e.headers.get("cookie") ?? "", this.setCookieHeader = t;
|
|
624
632
|
}
|
|
625
633
|
get(e, t) {
|
|
626
|
-
return
|
|
634
|
+
return T(this.raw, t)[e];
|
|
627
635
|
}
|
|
628
636
|
getAll(e) {
|
|
629
|
-
return Object.entries(
|
|
637
|
+
return Object.entries(T(this.raw, e)).filter(([, t]) => t !== void 0).map(([t, s]) => ({ name: t, value: s }));
|
|
630
638
|
}
|
|
631
639
|
set(e, t, s) {
|
|
632
|
-
this.setCookieHeader(
|
|
640
|
+
this.setCookieHeader(Q(e, t, s));
|
|
633
641
|
}
|
|
634
642
|
delete(e, t) {
|
|
635
643
|
this.set(e, "", { ...t, maxAge: 0 });
|
|
636
644
|
}
|
|
637
645
|
}
|
|
638
|
-
class
|
|
646
|
+
class W extends Error {
|
|
639
647
|
constructor(e = "Payload Too Large") {
|
|
640
648
|
super(e), this.status = 413, this.name = "PayloadTooLargeError";
|
|
641
649
|
}
|
|
642
650
|
}
|
|
643
|
-
class be {
|
|
651
|
+
class be extends P {
|
|
644
652
|
constructor(e) {
|
|
645
|
-
this.upgradeHandlerInstalled = !1, this.config = e ?? { type: "http", options: {} }, this.
|
|
653
|
+
super(), this.upgradeHandlerInstalled = !1, this.config = e ?? { type: "http", options: {} }, this.wss = new Y({
|
|
646
654
|
noServer: !0,
|
|
647
655
|
maxPayload: this.config.security?.maxWebSocketPayload ?? 1024 * 1024
|
|
648
656
|
});
|
|
@@ -654,13 +662,10 @@ class be {
|
|
|
654
662
|
console.error("Unhandled request error:", r), s.statusCode = 500, s.end("Internal Server Error");
|
|
655
663
|
});
|
|
656
664
|
};
|
|
657
|
-
this._server = this.config.type === "https" ?
|
|
665
|
+
this._server = this.config.type === "https" ? X(this.config.options, e) : q(this.config.options, e);
|
|
658
666
|
}
|
|
659
667
|
return this._server;
|
|
660
668
|
}
|
|
661
|
-
discard(e, t) {
|
|
662
|
-
return this.router.discard(e, t), this;
|
|
663
|
-
}
|
|
664
669
|
listen(...e) {
|
|
665
670
|
return this.upgradeHandlerInstalled || (this.installUpgradeHandler(), this.upgradeHandlerInstalled = !0), this.server.listen(...e), this;
|
|
666
671
|
}
|
|
@@ -684,16 +689,16 @@ class be {
|
|
|
684
689
|
pushSetCookie: () => {
|
|
685
690
|
}
|
|
686
691
|
});
|
|
687
|
-
this.
|
|
692
|
+
this.canHandleWebSocket(o).then((i) => {
|
|
688
693
|
if (!i || !this.isAllowedWebSocketOrigin(e)) {
|
|
689
694
|
t.destroy();
|
|
690
695
|
return;
|
|
691
696
|
}
|
|
692
697
|
this.wss.handleUpgrade(e, t, s, (u) => {
|
|
693
|
-
this.
|
|
694
|
-
!c && u.readyState ===
|
|
698
|
+
this.handleWebSocket(o, u).then((c) => {
|
|
699
|
+
!c && u.readyState === E.OPEN && u.close(1008, "Route not found");
|
|
695
700
|
}).catch((c) => {
|
|
696
|
-
console.error("WebSocket routing error:", c), u.readyState ===
|
|
701
|
+
console.error("WebSocket routing error:", c), u.readyState === E.OPEN && u.close(1011, "Internal error");
|
|
697
702
|
});
|
|
698
703
|
});
|
|
699
704
|
}).catch(() => t.destroy());
|
|
@@ -726,7 +731,7 @@ class be {
|
|
|
726
731
|
});
|
|
727
732
|
let u;
|
|
728
733
|
try {
|
|
729
|
-
u = await this.
|
|
734
|
+
u = await this.handle(i);
|
|
730
735
|
} catch (c) {
|
|
731
736
|
u = this.handleError(c);
|
|
732
737
|
}
|
|
@@ -745,17 +750,17 @@ class be {
|
|
|
745
750
|
// @ts-ignore
|
|
746
751
|
duplex: "half"
|
|
747
752
|
};
|
|
748
|
-
return !s && e.method !== "GET" && e.method !== "HEAD" && (r.body =
|
|
753
|
+
return !s && e.method !== "GET" && e.method !== "HEAD" && (r.body = J.toWeb(this.wrapRequestBody(e))), new Request(t, r);
|
|
749
754
|
}
|
|
750
755
|
wrapRequestBody(e) {
|
|
751
756
|
const t = this.config.security?.maxRequestBodySize;
|
|
752
757
|
if (!t)
|
|
753
758
|
return e;
|
|
754
759
|
let s = 0;
|
|
755
|
-
const r = new
|
|
760
|
+
const r = new V({
|
|
756
761
|
transform(n, o, i) {
|
|
757
762
|
if (s += Buffer.byteLength(n), s > t) {
|
|
758
|
-
i(new
|
|
763
|
+
i(new W());
|
|
759
764
|
return;
|
|
760
765
|
}
|
|
761
766
|
i(null, n);
|
|
@@ -764,7 +769,7 @@ class be {
|
|
|
764
769
|
return e.on("aborted", () => r.destroy(new Error("Request aborted"))), e.on("error", (n) => r.destroy(n)), e.pipe(r), r;
|
|
765
770
|
}
|
|
766
771
|
toURL(e, t) {
|
|
767
|
-
const s = e.socket instanceof
|
|
772
|
+
const s = e.socket instanceof G ? t ? "wss" : "https" : t ? "ws" : "http", r = this.resolveAuthority(e);
|
|
768
773
|
return new URL(e.url ?? "/", `${s}://${r}`);
|
|
769
774
|
}
|
|
770
775
|
resolveAuthority(e) {
|
|
@@ -812,9 +817,9 @@ class be {
|
|
|
812
817
|
return Number.isFinite(r) && r <= t;
|
|
813
818
|
}
|
|
814
819
|
handleError(e) {
|
|
815
|
-
if (e instanceof
|
|
820
|
+
if (e instanceof W)
|
|
816
821
|
return new Response(e.message, { status: e.status });
|
|
817
|
-
if (
|
|
822
|
+
if (N(e))
|
|
818
823
|
return new Response(JSON.stringify({
|
|
819
824
|
error: e.statusText || "Error",
|
|
820
825
|
status: e.status
|
|
@@ -822,7 +827,7 @@ class be {
|
|
|
822
827
|
status: e.status,
|
|
823
828
|
headers: { "Content-Type": "application/json" }
|
|
824
829
|
});
|
|
825
|
-
if (
|
|
830
|
+
if (j(e)) {
|
|
826
831
|
const t = e.headers.get("Location") || "/";
|
|
827
832
|
return new Response(null, {
|
|
828
833
|
status: e.status,
|
|
@@ -838,7 +843,7 @@ class be {
|
|
|
838
843
|
e.end();
|
|
839
844
|
return;
|
|
840
845
|
}
|
|
841
|
-
const s = t.body.getReader(), r =
|
|
846
|
+
const s = t.body.getReader(), r = K.toWeb(e).getWriter();
|
|
842
847
|
try {
|
|
843
848
|
for (; ; ) {
|
|
844
849
|
const { done: n, value: o } = await s.read();
|
|
@@ -860,7 +865,7 @@ class be {
|
|
|
860
865
|
return s ? this.matchesValue(t, s) : !0;
|
|
861
866
|
}
|
|
862
867
|
toRequestEvent(e, t, s) {
|
|
863
|
-
const r = new
|
|
868
|
+
const r = new me(e, s.pushSetCookie), n = this.config, o = {}, i = { name: "WebHTTPServer" }, u = /* @__PURE__ */ new Set(), c = {
|
|
864
869
|
request: e,
|
|
865
870
|
url: t,
|
|
866
871
|
cookies: r,
|
|
@@ -887,7 +892,7 @@ class be {
|
|
|
887
892
|
return n.locals && Object.assign(o, n.locals(c)), n.platform && Object.assign(i, n.platform(c)), c;
|
|
888
893
|
}
|
|
889
894
|
}
|
|
890
|
-
const
|
|
895
|
+
const We = async (a, e) => {
|
|
891
896
|
const t = JSON.stringify(await a);
|
|
892
897
|
return new Response(t, {
|
|
893
898
|
...e,
|
|
@@ -897,7 +902,24 @@ const Ce = async (a, e) => {
|
|
|
897
902
|
...e?.headers
|
|
898
903
|
}
|
|
899
904
|
});
|
|
900
|
-
}
|
|
905
|
+
};
|
|
906
|
+
function Le(a, e) {
|
|
907
|
+
throw new Response(null, {
|
|
908
|
+
status: a,
|
|
909
|
+
headers: {
|
|
910
|
+
location: e.toString()
|
|
911
|
+
}
|
|
912
|
+
});
|
|
913
|
+
}
|
|
914
|
+
function Oe(a, e) {
|
|
915
|
+
throw new Response(JSON.stringify(typeof e == "string" ? { message: e } : e), {
|
|
916
|
+
status: a,
|
|
917
|
+
headers: {
|
|
918
|
+
"content-type": "application/json"
|
|
919
|
+
}
|
|
920
|
+
});
|
|
921
|
+
}
|
|
922
|
+
const ve = async (a, e) => {
|
|
901
923
|
const t = await a;
|
|
902
924
|
return new Response(t, {
|
|
903
925
|
...e,
|
|
@@ -907,7 +929,7 @@ const Ce = async (a, e) => {
|
|
|
907
929
|
...e?.headers
|
|
908
930
|
}
|
|
909
931
|
});
|
|
910
|
-
},
|
|
932
|
+
}, _e = async (a, e) => {
|
|
911
933
|
const t = await a;
|
|
912
934
|
return new Response(t, {
|
|
913
935
|
...e,
|
|
@@ -917,20 +939,23 @@ const Ce = async (a, e) => {
|
|
|
917
939
|
...e?.headers
|
|
918
940
|
}
|
|
919
941
|
});
|
|
920
|
-
},
|
|
942
|
+
}, Ne = (a, e = {}) => (t) => te(a, t, e);
|
|
921
943
|
export {
|
|
922
944
|
R as Action,
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
945
|
+
Ce as CORS,
|
|
946
|
+
Te as RateLimiter,
|
|
947
|
+
pe as RequestMethods,
|
|
948
|
+
P as Router,
|
|
927
949
|
be as WebServer,
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
N as
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
We as
|
|
950
|
+
Ne as dir,
|
|
951
|
+
Oe as error,
|
|
952
|
+
_e as html,
|
|
953
|
+
N as isHttpError,
|
|
954
|
+
j as isRedirect,
|
|
955
|
+
x as isResponse,
|
|
956
|
+
We as json,
|
|
957
|
+
Le as redirect,
|
|
958
|
+
te as serveStatic,
|
|
959
|
+
ve as text
|
|
935
960
|
};
|
|
936
961
|
//# sourceMappingURL=index.es.js.map
|