@marko/run 0.5.17 → 0.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/dist/.tsbuildinfo +1 -1
- package/dist/adapter/index.cjs +71 -193
- package/dist/adapter/index.js +71 -193
- package/dist/adapter/middleware.cjs +70 -202
- package/dist/adapter/middleware.js +70 -192
- package/dist/cli/index.mjs +30 -31
- package/dist/runtime/internal.cjs +1 -1
- package/dist/runtime/internal.js +1 -1
- package/dist/vite/index.cjs +30 -31
- package/dist/vite/index.js +30 -31
- package/package.json +12 -13
- package/dist/adapter/polyfill.d.ts +0 -11
package/dist/adapter/index.cjs
CHANGED
|
@@ -412,76 +412,6 @@ function createAnimationManager(options = {}) {
|
|
|
412
412
|
|
|
413
413
|
// src/adapter/middleware.ts
|
|
414
414
|
var import_node_stream = require("node:stream");
|
|
415
|
-
|
|
416
|
-
// src/adapter/polyfill.ts
|
|
417
|
-
var import_crypto = require("crypto");
|
|
418
|
-
var import_http = require("http");
|
|
419
|
-
var webStream = __toESM(require("stream/web"), 1);
|
|
420
|
-
var undici = __toESM(require("undici"), 1);
|
|
421
|
-
globalThis.crypto ?? (globalThis.crypto = import_crypto.webcrypto);
|
|
422
|
-
globalThis.fetch ?? (globalThis.fetch = undici.fetch);
|
|
423
|
-
globalThis.Response ?? (globalThis.Response = undici.Response);
|
|
424
|
-
globalThis.Request ?? (globalThis.Request = undici.Request);
|
|
425
|
-
globalThis.Headers ?? (globalThis.Headers = undici.Headers);
|
|
426
|
-
globalThis.ReadableStream ?? (globalThis.ReadableStream = webStream.ReadableStream);
|
|
427
|
-
globalThis.TransformStream ?? (globalThis.TransformStream = webStream.TransformStream);
|
|
428
|
-
globalThis.WritableStream ?? (globalThis.WritableStream = webStream.WritableStream);
|
|
429
|
-
globalThis.FormData ?? (globalThis.FormData = undici.FormData);
|
|
430
|
-
globalThis.File ?? (globalThis.File = undici.File);
|
|
431
|
-
var appendHeader = import_http.ServerResponse.prototype.appendHeader ? appendHeader_platform : appendHeader_fallback;
|
|
432
|
-
function appendHeader_platform(response, name, value) {
|
|
433
|
-
response.appendHeader(name, value);
|
|
434
|
-
}
|
|
435
|
-
function appendHeader_fallback(response, name, value) {
|
|
436
|
-
const existing = response.getHeader(name);
|
|
437
|
-
if (existing === void 0) {
|
|
438
|
-
response.setHeader(name, value);
|
|
439
|
-
} else if (Array.isArray(existing)) {
|
|
440
|
-
response.setHeader(name, existing.concat(value));
|
|
441
|
-
} else {
|
|
442
|
-
response.setHeader(name, [String(existing)].concat(value));
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
var getSetCookie = Headers.prototype.getSetCookie ? getSetCookie_platform : getSetCookie_fallback;
|
|
446
|
-
function getSetCookie_platform(headers) {
|
|
447
|
-
return headers.getSetCookie();
|
|
448
|
-
}
|
|
449
|
-
var inExpiresDateRgs = /Expires\s*=\s*(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun)\s*$/i;
|
|
450
|
-
function getSetCookie_fallback(headers) {
|
|
451
|
-
const value = headers.get("set-cookie");
|
|
452
|
-
if (!value) return void 0;
|
|
453
|
-
let sepIndex = value.indexOf(",") + 1;
|
|
454
|
-
if (!sepIndex) return value;
|
|
455
|
-
let index = 0;
|
|
456
|
-
let setCookie = void 0;
|
|
457
|
-
let setCookies = void 0;
|
|
458
|
-
do {
|
|
459
|
-
const valuePart = value.slice(index, sepIndex - 1);
|
|
460
|
-
if (!inExpiresDateRgs.test(valuePart)) {
|
|
461
|
-
if (setCookies) {
|
|
462
|
-
setCookies.push(valuePart);
|
|
463
|
-
} else if (setCookie) {
|
|
464
|
-
setCookies = [setCookie, valuePart];
|
|
465
|
-
} else {
|
|
466
|
-
setCookie = valuePart;
|
|
467
|
-
}
|
|
468
|
-
index = sepIndex;
|
|
469
|
-
while (value.charCodeAt(index) === 32) index++;
|
|
470
|
-
}
|
|
471
|
-
sepIndex = value.indexOf(",", sepIndex) + 1;
|
|
472
|
-
} while (sepIndex);
|
|
473
|
-
if (index) {
|
|
474
|
-
const valuePart = value.slice(index);
|
|
475
|
-
if (setCookies) {
|
|
476
|
-
setCookies.push(valuePart);
|
|
477
|
-
return setCookies;
|
|
478
|
-
}
|
|
479
|
-
return [setCookie, valuePart];
|
|
480
|
-
}
|
|
481
|
-
return value;
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
// src/adapter/middleware.ts
|
|
485
415
|
function getForwardedHeader(req, name) {
|
|
486
416
|
const value = req.headers["x-forwarded-" + name];
|
|
487
417
|
if (value) {
|
|
@@ -496,7 +426,7 @@ function getOrigin(req, trustProxy) {
|
|
|
496
426
|
const protocol = trustProxy && getForwardedHeader(req, "proto") || req.socket.encrypted && "https" || req.protocol || "http";
|
|
497
427
|
let host = trustProxy && getForwardedHeader(req, "host") || req.headers.host;
|
|
498
428
|
if (!host) {
|
|
499
|
-
if (process.env.NODE_ENV
|
|
429
|
+
if (!process.env.NODE_ENV || process.env.NODE_ENV === "development") {
|
|
500
430
|
host = "localhost";
|
|
501
431
|
console.warn(
|
|
502
432
|
`Could not automatically determine the origin host, using 'localhost'. Use the 'origin' option or the 'ORIGIN' environment variable to set the origin explicitly.`
|
|
@@ -515,147 +445,95 @@ function copyResponseHeaders(response, headers) {
|
|
|
515
445
|
response.setHeader(key, value);
|
|
516
446
|
}
|
|
517
447
|
}
|
|
518
|
-
const setCookies = getSetCookie(
|
|
448
|
+
const setCookies = headers.getSetCookie();
|
|
519
449
|
if (setCookies == null ? void 0 : setCookies.length) {
|
|
520
|
-
appendHeader(
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
function normalizeError(error) {
|
|
524
|
-
if (error.cause && !error.message) {
|
|
525
|
-
error.message = error.cause.message;
|
|
526
|
-
error.stack || (error.stack = error.cause.stack);
|
|
450
|
+
response.appendHeader("set-cookie", setCookies);
|
|
527
451
|
}
|
|
528
|
-
return error;
|
|
529
452
|
}
|
|
530
|
-
function createMiddleware(
|
|
453
|
+
function createMiddleware(fetch, options) {
|
|
531
454
|
const {
|
|
532
455
|
origin = process.env.ORIGIN,
|
|
533
456
|
trustProxy = process.env.TRUST_PROXY === "1",
|
|
534
457
|
createPlatform = (platform) => platform
|
|
535
458
|
} = options ?? (options = {});
|
|
536
459
|
return async (req, res, next) => {
|
|
537
|
-
var _a;
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
res.on("close", onErrorOrClose);
|
|
545
|
-
signal.addEventListener("abort", onSignalAborted);
|
|
546
|
-
function onErrorOrClose(err) {
|
|
547
|
-
req.off("error", onErrorOrClose);
|
|
548
|
-
req.socket.off("error", onErrorOrClose);
|
|
549
|
-
res.off("error", onErrorOrClose);
|
|
550
|
-
res.off("close", onErrorOrClose);
|
|
551
|
-
if (err) {
|
|
552
|
-
signal.removeEventListener("abort", onSignalAborted);
|
|
553
|
-
controller.abort(err);
|
|
460
|
+
var _a, _b, _c, _d;
|
|
461
|
+
try {
|
|
462
|
+
if ((!process.env.NODE_ENV || process.env.NODE_ENV === "development") && globalThis.__marko_run_dev__ && ((_a = req.headers.accept) == null ? void 0 : _a.includes("text/html"))) {
|
|
463
|
+
var devWebSocket;
|
|
464
|
+
globalThis.__marko_run_dev__.onClient(res, (ws) => {
|
|
465
|
+
devWebSocket = ws;
|
|
466
|
+
});
|
|
554
467
|
}
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
468
|
+
let body;
|
|
469
|
+
switch (req.method) {
|
|
470
|
+
case "POST":
|
|
471
|
+
case "PUT":
|
|
472
|
+
case "PATCH":
|
|
473
|
+
if (import_node_stream.Readable.isDisturbed(req)) {
|
|
474
|
+
body = bodyConsumedErrorStream;
|
|
475
|
+
} else {
|
|
476
|
+
body = req;
|
|
477
|
+
}
|
|
478
|
+
break;
|
|
565
479
|
}
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
}
|
|
574
|
-
function sendError() {
|
|
575
|
-
const { message, stack = "" } = normalizeError(signal.reason);
|
|
576
|
-
ws.send(
|
|
577
|
-
JSON.stringify({
|
|
578
|
-
type: "error",
|
|
579
|
-
err: { message, stack }
|
|
580
|
-
})
|
|
581
|
-
);
|
|
582
|
-
}
|
|
480
|
+
const url = new URL(req.url, origin || getOrigin(req, trustProxy));
|
|
481
|
+
const request = new Request(url, {
|
|
482
|
+
method: req.method,
|
|
483
|
+
headers: req.headers,
|
|
484
|
+
body,
|
|
485
|
+
// @ts-expect-error: Node requires this for streams
|
|
486
|
+
duplex: "half"
|
|
583
487
|
});
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
488
|
+
const platform = createPlatform({
|
|
489
|
+
request: req,
|
|
490
|
+
response: res
|
|
491
|
+
});
|
|
492
|
+
const response = await fetch(request, platform);
|
|
493
|
+
if (res.destroyed || res.headersSent) {
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
if (response) {
|
|
497
|
+
res.statusCode = response.status;
|
|
498
|
+
copyResponseHeaders(res, response.headers);
|
|
499
|
+
if (response.body) {
|
|
500
|
+
for await (const chunk of response.body) {
|
|
501
|
+
if (res.destroyed) return;
|
|
502
|
+
res.write(chunk);
|
|
503
|
+
(_b = res.flush) == null ? void 0 : _b.call(res);
|
|
504
|
+
}
|
|
505
|
+
} else if (!response.headers.has("content-length")) {
|
|
506
|
+
res.setHeader("content-length", "0");
|
|
594
507
|
}
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
method: req.method,
|
|
599
|
-
headers: req.headers,
|
|
600
|
-
body,
|
|
601
|
-
// @ts-expect-error: Node requires this for streams
|
|
602
|
-
duplex: "half",
|
|
603
|
-
signal
|
|
604
|
-
});
|
|
605
|
-
const platform = createPlatform({
|
|
606
|
-
request: req,
|
|
607
|
-
response: res
|
|
608
|
-
});
|
|
609
|
-
let response;
|
|
610
|
-
try {
|
|
611
|
-
response = await fetch2(request, platform);
|
|
612
|
-
} catch (err) {
|
|
613
|
-
normalizeError(err);
|
|
614
|
-
if (next) {
|
|
615
|
-
next(err);
|
|
508
|
+
res.end();
|
|
509
|
+
} else if (next) {
|
|
510
|
+
next();
|
|
616
511
|
} else {
|
|
617
|
-
|
|
512
|
+
(_c = res.socket) == null ? void 0 : _c.destroySoon();
|
|
618
513
|
}
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
514
|
+
} catch (err) {
|
|
515
|
+
const error = err;
|
|
516
|
+
if (!process.env.NODE_ENV || process.env.NODE_ENV === "development") {
|
|
517
|
+
if (error.cause && !error.message) {
|
|
518
|
+
error.message = error.cause.message;
|
|
519
|
+
error.stack || (error.stack = error.cause.stack);
|
|
520
|
+
}
|
|
521
|
+
devWebSocket == null ? void 0 : devWebSocket.send(
|
|
522
|
+
JSON.stringify({
|
|
523
|
+
type: "error",
|
|
524
|
+
error: { message: error.message, stack: error.stack }
|
|
525
|
+
})
|
|
526
|
+
);
|
|
624
527
|
}
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
if (!response.headers.has("content-length")) {
|
|
631
|
-
res.setHeader("content-length", "0");
|
|
528
|
+
if (next) {
|
|
529
|
+
next(error);
|
|
530
|
+
} else {
|
|
531
|
+
(_d = res.socket) == null ? void 0 : _d.destroySoon();
|
|
532
|
+
console.error(error);
|
|
632
533
|
}
|
|
633
|
-
res.end();
|
|
634
|
-
return;
|
|
635
|
-
} else if (res.destroyed) {
|
|
636
|
-
controller.abort(new Error("Response stream destroyed"));
|
|
637
|
-
return;
|
|
638
534
|
}
|
|
639
|
-
writeResponse(response.body.getReader(), res, controller);
|
|
640
535
|
};
|
|
641
536
|
}
|
|
642
|
-
async function writeResponse(reader, res, controller) {
|
|
643
|
-
try {
|
|
644
|
-
while (!controller.signal.aborted) {
|
|
645
|
-
const { done, value } = await reader.read();
|
|
646
|
-
if (done) {
|
|
647
|
-
res.end();
|
|
648
|
-
return;
|
|
649
|
-
}
|
|
650
|
-
res.write(value);
|
|
651
|
-
if (res.flush) {
|
|
652
|
-
res.flush();
|
|
653
|
-
}
|
|
654
|
-
}
|
|
655
|
-
} catch (err) {
|
|
656
|
-
controller.abort(err);
|
|
657
|
-
}
|
|
658
|
-
}
|
|
659
537
|
var bodyConsumedErrorStream = new ReadableStream({
|
|
660
538
|
pull(controller) {
|
|
661
539
|
controller.error(
|
|
@@ -694,7 +572,7 @@ function logInfoBox(address, explorer) {
|
|
|
694
572
|
const color = !!import_supports_color.default.stdout;
|
|
695
573
|
let message = import_kleur2.default.bold("Marko Run");
|
|
696
574
|
if (true) {
|
|
697
|
-
message += ` v${"0.
|
|
575
|
+
message += ` v${"0.6.0"}`;
|
|
698
576
|
}
|
|
699
577
|
message += "\n\n";
|
|
700
578
|
message += import_kleur2.default.dim("Server listening at");
|
package/dist/adapter/index.js
CHANGED
|
@@ -371,76 +371,6 @@ function createAnimationManager(options = {}) {
|
|
|
371
371
|
|
|
372
372
|
// src/adapter/middleware.ts
|
|
373
373
|
import { Readable } from "node:stream";
|
|
374
|
-
|
|
375
|
-
// src/adapter/polyfill.ts
|
|
376
|
-
import { webcrypto } from "crypto";
|
|
377
|
-
import { ServerResponse } from "http";
|
|
378
|
-
import * as webStream from "stream/web";
|
|
379
|
-
import * as undici from "undici";
|
|
380
|
-
globalThis.crypto ?? (globalThis.crypto = webcrypto);
|
|
381
|
-
globalThis.fetch ?? (globalThis.fetch = undici.fetch);
|
|
382
|
-
globalThis.Response ?? (globalThis.Response = undici.Response);
|
|
383
|
-
globalThis.Request ?? (globalThis.Request = undici.Request);
|
|
384
|
-
globalThis.Headers ?? (globalThis.Headers = undici.Headers);
|
|
385
|
-
globalThis.ReadableStream ?? (globalThis.ReadableStream = webStream.ReadableStream);
|
|
386
|
-
globalThis.TransformStream ?? (globalThis.TransformStream = webStream.TransformStream);
|
|
387
|
-
globalThis.WritableStream ?? (globalThis.WritableStream = webStream.WritableStream);
|
|
388
|
-
globalThis.FormData ?? (globalThis.FormData = undici.FormData);
|
|
389
|
-
globalThis.File ?? (globalThis.File = undici.File);
|
|
390
|
-
var appendHeader = ServerResponse.prototype.appendHeader ? appendHeader_platform : appendHeader_fallback;
|
|
391
|
-
function appendHeader_platform(response, name, value) {
|
|
392
|
-
response.appendHeader(name, value);
|
|
393
|
-
}
|
|
394
|
-
function appendHeader_fallback(response, name, value) {
|
|
395
|
-
const existing = response.getHeader(name);
|
|
396
|
-
if (existing === void 0) {
|
|
397
|
-
response.setHeader(name, value);
|
|
398
|
-
} else if (Array.isArray(existing)) {
|
|
399
|
-
response.setHeader(name, existing.concat(value));
|
|
400
|
-
} else {
|
|
401
|
-
response.setHeader(name, [String(existing)].concat(value));
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
var getSetCookie = Headers.prototype.getSetCookie ? getSetCookie_platform : getSetCookie_fallback;
|
|
405
|
-
function getSetCookie_platform(headers) {
|
|
406
|
-
return headers.getSetCookie();
|
|
407
|
-
}
|
|
408
|
-
var inExpiresDateRgs = /Expires\s*=\s*(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun)\s*$/i;
|
|
409
|
-
function getSetCookie_fallback(headers) {
|
|
410
|
-
const value = headers.get("set-cookie");
|
|
411
|
-
if (!value) return void 0;
|
|
412
|
-
let sepIndex = value.indexOf(",") + 1;
|
|
413
|
-
if (!sepIndex) return value;
|
|
414
|
-
let index = 0;
|
|
415
|
-
let setCookie = void 0;
|
|
416
|
-
let setCookies = void 0;
|
|
417
|
-
do {
|
|
418
|
-
const valuePart = value.slice(index, sepIndex - 1);
|
|
419
|
-
if (!inExpiresDateRgs.test(valuePart)) {
|
|
420
|
-
if (setCookies) {
|
|
421
|
-
setCookies.push(valuePart);
|
|
422
|
-
} else if (setCookie) {
|
|
423
|
-
setCookies = [setCookie, valuePart];
|
|
424
|
-
} else {
|
|
425
|
-
setCookie = valuePart;
|
|
426
|
-
}
|
|
427
|
-
index = sepIndex;
|
|
428
|
-
while (value.charCodeAt(index) === 32) index++;
|
|
429
|
-
}
|
|
430
|
-
sepIndex = value.indexOf(",", sepIndex) + 1;
|
|
431
|
-
} while (sepIndex);
|
|
432
|
-
if (index) {
|
|
433
|
-
const valuePart = value.slice(index);
|
|
434
|
-
if (setCookies) {
|
|
435
|
-
setCookies.push(valuePart);
|
|
436
|
-
return setCookies;
|
|
437
|
-
}
|
|
438
|
-
return [setCookie, valuePart];
|
|
439
|
-
}
|
|
440
|
-
return value;
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
// src/adapter/middleware.ts
|
|
444
374
|
function getForwardedHeader(req, name) {
|
|
445
375
|
const value = req.headers["x-forwarded-" + name];
|
|
446
376
|
if (value) {
|
|
@@ -455,7 +385,7 @@ function getOrigin(req, trustProxy) {
|
|
|
455
385
|
const protocol = trustProxy && getForwardedHeader(req, "proto") || req.socket.encrypted && "https" || req.protocol || "http";
|
|
456
386
|
let host = trustProxy && getForwardedHeader(req, "host") || req.headers.host;
|
|
457
387
|
if (!host) {
|
|
458
|
-
if (process.env.NODE_ENV
|
|
388
|
+
if (!process.env.NODE_ENV || process.env.NODE_ENV === "development") {
|
|
459
389
|
host = "localhost";
|
|
460
390
|
console.warn(
|
|
461
391
|
`Could not automatically determine the origin host, using 'localhost'. Use the 'origin' option or the 'ORIGIN' environment variable to set the origin explicitly.`
|
|
@@ -474,147 +404,95 @@ function copyResponseHeaders(response, headers) {
|
|
|
474
404
|
response.setHeader(key, value);
|
|
475
405
|
}
|
|
476
406
|
}
|
|
477
|
-
const setCookies = getSetCookie(
|
|
407
|
+
const setCookies = headers.getSetCookie();
|
|
478
408
|
if (setCookies == null ? void 0 : setCookies.length) {
|
|
479
|
-
appendHeader(
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
function normalizeError(error) {
|
|
483
|
-
if (error.cause && !error.message) {
|
|
484
|
-
error.message = error.cause.message;
|
|
485
|
-
error.stack || (error.stack = error.cause.stack);
|
|
409
|
+
response.appendHeader("set-cookie", setCookies);
|
|
486
410
|
}
|
|
487
|
-
return error;
|
|
488
411
|
}
|
|
489
|
-
function createMiddleware(
|
|
412
|
+
function createMiddleware(fetch, options) {
|
|
490
413
|
const {
|
|
491
414
|
origin = process.env.ORIGIN,
|
|
492
415
|
trustProxy = process.env.TRUST_PROXY === "1",
|
|
493
416
|
createPlatform = (platform) => platform
|
|
494
417
|
} = options ?? (options = {});
|
|
495
418
|
return async (req, res, next) => {
|
|
496
|
-
var _a;
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
res.on("close", onErrorOrClose);
|
|
504
|
-
signal.addEventListener("abort", onSignalAborted);
|
|
505
|
-
function onErrorOrClose(err) {
|
|
506
|
-
req.off("error", onErrorOrClose);
|
|
507
|
-
req.socket.off("error", onErrorOrClose);
|
|
508
|
-
res.off("error", onErrorOrClose);
|
|
509
|
-
res.off("close", onErrorOrClose);
|
|
510
|
-
if (err) {
|
|
511
|
-
signal.removeEventListener("abort", onSignalAborted);
|
|
512
|
-
controller.abort(err);
|
|
419
|
+
var _a, _b, _c, _d;
|
|
420
|
+
try {
|
|
421
|
+
if ((!process.env.NODE_ENV || process.env.NODE_ENV === "development") && globalThis.__marko_run_dev__ && ((_a = req.headers.accept) == null ? void 0 : _a.includes("text/html"))) {
|
|
422
|
+
var devWebSocket;
|
|
423
|
+
globalThis.__marko_run_dev__.onClient(res, (ws) => {
|
|
424
|
+
devWebSocket = ws;
|
|
425
|
+
});
|
|
513
426
|
}
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
427
|
+
let body;
|
|
428
|
+
switch (req.method) {
|
|
429
|
+
case "POST":
|
|
430
|
+
case "PUT":
|
|
431
|
+
case "PATCH":
|
|
432
|
+
if (Readable.isDisturbed(req)) {
|
|
433
|
+
body = bodyConsumedErrorStream;
|
|
434
|
+
} else {
|
|
435
|
+
body = req;
|
|
436
|
+
}
|
|
437
|
+
break;
|
|
524
438
|
}
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
}
|
|
533
|
-
function sendError() {
|
|
534
|
-
const { message, stack = "" } = normalizeError(signal.reason);
|
|
535
|
-
ws.send(
|
|
536
|
-
JSON.stringify({
|
|
537
|
-
type: "error",
|
|
538
|
-
err: { message, stack }
|
|
539
|
-
})
|
|
540
|
-
);
|
|
541
|
-
}
|
|
439
|
+
const url = new URL(req.url, origin || getOrigin(req, trustProxy));
|
|
440
|
+
const request = new Request(url, {
|
|
441
|
+
method: req.method,
|
|
442
|
+
headers: req.headers,
|
|
443
|
+
body,
|
|
444
|
+
// @ts-expect-error: Node requires this for streams
|
|
445
|
+
duplex: "half"
|
|
542
446
|
});
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
447
|
+
const platform = createPlatform({
|
|
448
|
+
request: req,
|
|
449
|
+
response: res
|
|
450
|
+
});
|
|
451
|
+
const response = await fetch(request, platform);
|
|
452
|
+
if (res.destroyed || res.headersSent) {
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
455
|
+
if (response) {
|
|
456
|
+
res.statusCode = response.status;
|
|
457
|
+
copyResponseHeaders(res, response.headers);
|
|
458
|
+
if (response.body) {
|
|
459
|
+
for await (const chunk of response.body) {
|
|
460
|
+
if (res.destroyed) return;
|
|
461
|
+
res.write(chunk);
|
|
462
|
+
(_b = res.flush) == null ? void 0 : _b.call(res);
|
|
463
|
+
}
|
|
464
|
+
} else if (!response.headers.has("content-length")) {
|
|
465
|
+
res.setHeader("content-length", "0");
|
|
553
466
|
}
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
method: req.method,
|
|
558
|
-
headers: req.headers,
|
|
559
|
-
body,
|
|
560
|
-
// @ts-expect-error: Node requires this for streams
|
|
561
|
-
duplex: "half",
|
|
562
|
-
signal
|
|
563
|
-
});
|
|
564
|
-
const platform = createPlatform({
|
|
565
|
-
request: req,
|
|
566
|
-
response: res
|
|
567
|
-
});
|
|
568
|
-
let response;
|
|
569
|
-
try {
|
|
570
|
-
response = await fetch2(request, platform);
|
|
571
|
-
} catch (err) {
|
|
572
|
-
normalizeError(err);
|
|
573
|
-
if (next) {
|
|
574
|
-
next(err);
|
|
467
|
+
res.end();
|
|
468
|
+
} else if (next) {
|
|
469
|
+
next();
|
|
575
470
|
} else {
|
|
576
|
-
|
|
471
|
+
(_c = res.socket) == null ? void 0 : _c.destroySoon();
|
|
577
472
|
}
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
473
|
+
} catch (err) {
|
|
474
|
+
const error = err;
|
|
475
|
+
if (!process.env.NODE_ENV || process.env.NODE_ENV === "development") {
|
|
476
|
+
if (error.cause && !error.message) {
|
|
477
|
+
error.message = error.cause.message;
|
|
478
|
+
error.stack || (error.stack = error.cause.stack);
|
|
479
|
+
}
|
|
480
|
+
devWebSocket == null ? void 0 : devWebSocket.send(
|
|
481
|
+
JSON.stringify({
|
|
482
|
+
type: "error",
|
|
483
|
+
error: { message: error.message, stack: error.stack }
|
|
484
|
+
})
|
|
485
|
+
);
|
|
583
486
|
}
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
if (!response.headers.has("content-length")) {
|
|
590
|
-
res.setHeader("content-length", "0");
|
|
487
|
+
if (next) {
|
|
488
|
+
next(error);
|
|
489
|
+
} else {
|
|
490
|
+
(_d = res.socket) == null ? void 0 : _d.destroySoon();
|
|
491
|
+
console.error(error);
|
|
591
492
|
}
|
|
592
|
-
res.end();
|
|
593
|
-
return;
|
|
594
|
-
} else if (res.destroyed) {
|
|
595
|
-
controller.abort(new Error("Response stream destroyed"));
|
|
596
|
-
return;
|
|
597
493
|
}
|
|
598
|
-
writeResponse(response.body.getReader(), res, controller);
|
|
599
494
|
};
|
|
600
495
|
}
|
|
601
|
-
async function writeResponse(reader, res, controller) {
|
|
602
|
-
try {
|
|
603
|
-
while (!controller.signal.aborted) {
|
|
604
|
-
const { done, value } = await reader.read();
|
|
605
|
-
if (done) {
|
|
606
|
-
res.end();
|
|
607
|
-
return;
|
|
608
|
-
}
|
|
609
|
-
res.write(value);
|
|
610
|
-
if (res.flush) {
|
|
611
|
-
res.flush();
|
|
612
|
-
}
|
|
613
|
-
}
|
|
614
|
-
} catch (err) {
|
|
615
|
-
controller.abort(err);
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
496
|
var bodyConsumedErrorStream = new ReadableStream({
|
|
619
497
|
pull(controller) {
|
|
620
498
|
controller.error(
|
|
@@ -653,7 +531,7 @@ function logInfoBox(address, explorer) {
|
|
|
653
531
|
const color = !!supporsColor.stdout;
|
|
654
532
|
let message = kleur2.bold("Marko Run");
|
|
655
533
|
if (true) {
|
|
656
|
-
message += ` v${"0.
|
|
534
|
+
message += ` v${"0.6.0"}`;
|
|
657
535
|
}
|
|
658
536
|
message += "\n\n";
|
|
659
537
|
message += kleur2.dim("Server listening at");
|