@wooksjs/event-http 0.6.0 → 0.6.2
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/index.cjs +447 -69
- package/dist/index.d.ts +68 -0
- package/dist/index.mjs +422 -43
- package/package.json +7 -8
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
//#region rolldown:runtime
|
|
3
2
|
var __create = Object.create;
|
|
4
3
|
var __defProp = Object.defineProperty;
|
|
@@ -42,6 +41,10 @@ function createHttpContext(data, options) {
|
|
|
42
41
|
options
|
|
43
42
|
});
|
|
44
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* Wrapper on useEventContext with HTTP event types
|
|
46
|
+
* @returns set of hooks { getCtx, restoreCtx, clearCtx, hookStore, getStore, setStore }
|
|
47
|
+
*/
|
|
45
48
|
function useHttpContext() {
|
|
46
49
|
return (0, __wooksjs_event_core.useAsyncEventContext)("HTTP");
|
|
47
50
|
}
|
|
@@ -76,12 +79,12 @@ function convertTime(time, unit = "ms") {
|
|
|
76
79
|
const units = {
|
|
77
80
|
ms: 1,
|
|
78
81
|
s: 1e3,
|
|
79
|
-
m:
|
|
80
|
-
h:
|
|
81
|
-
d:
|
|
82
|
-
w:
|
|
83
|
-
M:
|
|
84
|
-
Y:
|
|
82
|
+
m: 1e3 * 60,
|
|
83
|
+
h: 1e3 * 60 * 60,
|
|
84
|
+
d: 1e3 * 60 * 60 * 24,
|
|
85
|
+
w: 1e3 * 60 * 60 * 24 * 7,
|
|
86
|
+
M: 1e3 * 60 * 60 * 24 * 30,
|
|
87
|
+
Y: 1e3 * 60 * 60 * 24 * 365
|
|
85
88
|
};
|
|
86
89
|
|
|
87
90
|
//#endregion
|
|
@@ -191,7 +194,7 @@ var BaseHttpResponseRenderer = class {
|
|
|
191
194
|
if (!response.getContentType()) response.setContentType("text/plain");
|
|
192
195
|
return response.body.toString();
|
|
193
196
|
}
|
|
194
|
-
if (response.body ===
|
|
197
|
+
if (response.body === void 0) return "";
|
|
195
198
|
if (response.body instanceof Uint8Array) return response.body;
|
|
196
199
|
if (typeof response.body === "object") {
|
|
197
200
|
if (!response.getContentType()) response.setContentType("application/json");
|
|
@@ -268,7 +271,7 @@ const httpStatusCodes = {
|
|
|
268
271
|
510: "Not Extended",
|
|
269
272
|
511: "Network Authentication Required"
|
|
270
273
|
};
|
|
271
|
-
let EHttpStatusCode = function(EHttpStatusCode$1) {
|
|
274
|
+
let EHttpStatusCode = /* @__PURE__ */ function(EHttpStatusCode$1) {
|
|
272
275
|
EHttpStatusCode$1[EHttpStatusCode$1["Continue"] = 100] = "Continue";
|
|
273
276
|
EHttpStatusCode$1[EHttpStatusCode$1["SwitchingProtocols"] = 101] = "SwitchingProtocols";
|
|
274
277
|
EHttpStatusCode$1[EHttpStatusCode$1["Processing"] = 102] = "Processing";
|
|
@@ -335,24 +338,393 @@ let EHttpStatusCode = function(EHttpStatusCode$1) {
|
|
|
335
338
|
return EHttpStatusCode$1;
|
|
336
339
|
}({});
|
|
337
340
|
|
|
341
|
+
//#endregion
|
|
342
|
+
//#region packages/event-http/src/errors/403.tl.svg
|
|
343
|
+
function _403_tl_default(ctx) {
|
|
344
|
+
return `<svg height="64" viewBox="0 4 100 96" fill="none" xmlns="http://www.w3.org/2000/svg" stroke="#888888" stroke-width="2">
|
|
345
|
+
<path d="M50 90.625C64.4042 87.1875 83.5751 69.8667 83.5751 48.6937V24.0854L50 9.375L16.425 24.0833V48.6937C16.425 69.8667 35.5959 87.1875 50 90.625Z" fill="#ff000050">
|
|
346
|
+
<animate attributeName="fill" dur="2s" repeatCount="indefinite"
|
|
347
|
+
values="#ff000000;#ff000050;#ff000000" />
|
|
348
|
+
</path>
|
|
349
|
+
|
|
350
|
+
<path d="M61.5395 46.0812H38.4604C37.1061 46.0812 36.0083 47.1791 36.0083 48.5333V65.075C36.0083 66.4292 37.1061 67.5271 38.4604 67.5271H61.5395C62.8938 67.5271 63.9916 66.4292 63.9916 65.075V48.5333C63.9916 47.1791 62.8938 46.0812 61.5395 46.0812Z" />
|
|
351
|
+
|
|
352
|
+
<path d="M41.7834 46.0834V39.6813C41.7834 37.5021 42.6491 35.4121 44.1901 33.8712C45.731 32.3303 47.8209 31.4646 50.0001 31.4646C52.1793 31.4646 54.2693 32.3303 55.8102 33.8712C57.3511 35.4121 58.2168 37.5021 58.2168 39.6813V46.0813" />
|
|
353
|
+
</svg>
|
|
354
|
+
`;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
//#endregion
|
|
358
|
+
//#region packages/event-http/src/errors/404.tl.svg
|
|
359
|
+
function _404_tl_default(ctx) {
|
|
360
|
+
return `<svg height="64" viewBox="0 20 100 64" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
361
|
+
<defs>
|
|
362
|
+
<path id="sheet" d="M86.5 36.5V47.5H97.5V92.5H52.5V36.5H86.5ZM63 68.5H87V67.5H63V68.5ZM63 63.5H87V62.5H63V63.5ZM63 58.5H87V57.5H63V58.5ZM96.793 46.5H87.5V37.207L96.793 46.5Z" fill="#88888833" stroke="#888888aa"/>
|
|
363
|
+
</defs>
|
|
364
|
+
|
|
365
|
+
<g id="queue" transform="translate(-5 -10)">
|
|
366
|
+
<use href="#sheet" opacity="0">
|
|
367
|
+
<animateTransform attributeName="transform" type="translate"
|
|
368
|
+
dur="3s" repeatCount="indefinite"
|
|
369
|
+
keyTimes="0;0.1;0.32;0.42;1"
|
|
370
|
+
values="30 0; -20 0; -20 0; -70 0; -70 0" />
|
|
371
|
+
<animate attributeName="opacity"
|
|
372
|
+
dur="3s" repeatCount="indefinite"
|
|
373
|
+
keyTimes="0;0.1;0.32;0.42;1"
|
|
374
|
+
values="0;1;1;0;0" />
|
|
375
|
+
</use>
|
|
376
|
+
|
|
377
|
+
<use href="#sheet" opacity="0">
|
|
378
|
+
<animateTransform attributeName="transform" type="translate"
|
|
379
|
+
dur="3s" begin="1s" repeatCount="indefinite"
|
|
380
|
+
keyTimes="0;0.1;0.32;0.42;1"
|
|
381
|
+
values="30 0; -20 0; -20 0; -70 0; -70 0" />
|
|
382
|
+
<animate attributeName="opacity"
|
|
383
|
+
dur="3s" begin="1s" repeatCount="indefinite"
|
|
384
|
+
keyTimes="0;0.1;0.32;0.42;1"
|
|
385
|
+
values="0;1;1;0;0" />
|
|
386
|
+
</use>
|
|
387
|
+
|
|
388
|
+
<use href="#sheet" opacity="0">
|
|
389
|
+
<animateTransform attributeName="transform" type="translate"
|
|
390
|
+
dur="3s" begin="2s" repeatCount="indefinite"
|
|
391
|
+
keyTimes="0;0.1;0.32;0.42;1"
|
|
392
|
+
values="30 0; -20 0; -20 0; -70 0; -70 0" />
|
|
393
|
+
<animate attributeName="opacity"
|
|
394
|
+
dur="3s" begin="2s" repeatCount="indefinite"
|
|
395
|
+
keyTimes="0;0.1;0.32;0.42;1"
|
|
396
|
+
values="0;1;1;0;0" />
|
|
397
|
+
</use>
|
|
398
|
+
</g>
|
|
399
|
+
|
|
400
|
+
<g>
|
|
401
|
+
<path d="M49.5 32.5C58.3366 32.5 65.5 39.6634 65.5 48.5C65.5 54.4781 62.222 59.6923 57.3584 62.4404C55.0386 63.7512 52.3591 64.5 49.5 64.5C40.6634 64.5 33.5 57.3366 33.5 48.5C33.5 39.6634 40.6634 32.5 49.5 32.5Z" fill="#ffffff50" stroke="#888888" stroke-width="3"/>
|
|
402
|
+
|
|
403
|
+
<path d="M62.7101 74.5691C63.117 75.2907 64.0318 75.5459 64.7534 75.139C65.4751 74.7321 65.7302 73.8173 65.3233 73.0957L62.7101 74.5691ZM58.05 63.25L56.7434 63.9867L62.7101 74.5691L64.0167 73.8324L65.3233 73.0957L59.3567 62.5133L58.05 63.25Z" fill="#888888"/>
|
|
404
|
+
</g>
|
|
405
|
+
</svg>
|
|
406
|
+
|
|
407
|
+
`;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
//#endregion
|
|
411
|
+
//#region packages/event-http/src/errors/500.tl.svg
|
|
412
|
+
function _500_tl_default(ctx) {
|
|
413
|
+
return `<svg height="64" viewBox="0 0 120 100" xmlns="http://www.w3.org/2000/svg">
|
|
414
|
+
|
|
415
|
+
<g id="server">
|
|
416
|
+
|
|
417
|
+
<g fill="#88888888" stroke="#88888888" stroke-width="2" >
|
|
418
|
+
<path d="M18 90C13.5817 90 10 86.4182 10 82V38C10 33.5817 13.5817 30 18 30H50.5L58 43L52.5 53L56 68.5L49.0098 89.97L61.2141 71.4358L58.363 54.315L64.7769 43.5511L58.2763 30.2943L104.243 32.0434C108.658 32.2114 112.101 35.9267 111.933 40.3418L110.26 84.31C110.092 88.725 106.377 92.168 101.962 92L49 90H18Z" />
|
|
419
|
+
</g>
|
|
420
|
+
<circle cx="30" cy="60" r="6" fill="red">
|
|
421
|
+
<animate attributeName="fill" dur="0.8s"
|
|
422
|
+
values="red;#2d0000;red" repeatCount="indefinite"/>
|
|
423
|
+
</circle>
|
|
424
|
+
|
|
425
|
+
</g>
|
|
426
|
+
|
|
427
|
+
<g fill="lightgray" opacity="0.75">
|
|
428
|
+
<circle cx="50" cy="35" r="6">
|
|
429
|
+
<animate attributeName="cy" from="35" to="15" dur="2s"
|
|
430
|
+
repeatCount="indefinite"/>
|
|
431
|
+
<animate attributeName="opacity" values="0.75;0" dur="2s"
|
|
432
|
+
repeatCount="indefinite"/>
|
|
433
|
+
</circle>
|
|
434
|
+
<circle cx="60" cy="40" r="4">
|
|
435
|
+
<animate attributeName="cy" from="40" to="20" dur="2s"
|
|
436
|
+
begin="0.4s" repeatCount="indefinite"/>
|
|
437
|
+
<animate attributeName="opacity" values="0.75;0" dur="2s"
|
|
438
|
+
begin="0.4s" repeatCount="indefinite"/>
|
|
439
|
+
</circle>
|
|
440
|
+
</g>
|
|
441
|
+
|
|
442
|
+
</svg>
|
|
443
|
+
`;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
//#endregion
|
|
447
|
+
//#region packages/event-http/src/errors/error.tl.html
|
|
448
|
+
function error_tl_default(ctx) {
|
|
449
|
+
const { statusCode, statusMessage, icon, message, details, link, image, version } = ctx;
|
|
450
|
+
return `<!doctype html>
|
|
451
|
+
<html lang="en">
|
|
452
|
+
<head>
|
|
453
|
+
<meta charset="UTF-8" />
|
|
454
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
455
|
+
<title>${statusCode} ${statusMessage}</title>
|
|
456
|
+
<style>
|
|
457
|
+
body {
|
|
458
|
+
font-family: -apple-system, BlinkMacMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu,
|
|
459
|
+
Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
|
|
460
|
+
display: flex;
|
|
461
|
+
justify-content: center;
|
|
462
|
+
align-items: flex-start;
|
|
463
|
+
min-height: 100vh;
|
|
464
|
+
margin: 0;
|
|
465
|
+
padding: 0 20px;
|
|
466
|
+
box-sizing: border-box;
|
|
467
|
+
transition:
|
|
468
|
+
background-color 0.3s ease,
|
|
469
|
+
color 0.3s ease;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
.error-container {
|
|
473
|
+
padding: 48px;
|
|
474
|
+
padding-bottom: 12px !important;
|
|
475
|
+
background-color: #ffffff;
|
|
476
|
+
border-radius: 0 0 12px 12px;
|
|
477
|
+
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08);
|
|
478
|
+
text-align: center;
|
|
479
|
+
max-width: 650px;
|
|
480
|
+
width: 100%;
|
|
481
|
+
transition:
|
|
482
|
+
background-color 0.3s ease,
|
|
483
|
+
border-color 0.3s ease,
|
|
484
|
+
box-shadow 0.3s ease;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
.status-code {
|
|
488
|
+
font-size: 5rem;
|
|
489
|
+
font-weight: 900;
|
|
490
|
+
margin-bottom: 5px;
|
|
491
|
+
line-height: 1;
|
|
492
|
+
transition: color 0.3s ease;
|
|
493
|
+
display: flex;
|
|
494
|
+
align-items: center;
|
|
495
|
+
justify-content: center;
|
|
496
|
+
gap: 1rem;
|
|
497
|
+
position: relative;
|
|
498
|
+
margin-right: 24px;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
.status-text {
|
|
502
|
+
font-size: 2.25rem;
|
|
503
|
+
font-weight: 700;
|
|
504
|
+
margin-bottom: 25px;
|
|
505
|
+
transition: color 0.3s ease;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
.error-message {
|
|
509
|
+
font-size: 1.25rem;
|
|
510
|
+
margin-bottom: 40px;
|
|
511
|
+
line-height: 1.7;
|
|
512
|
+
transition: color 0.3s ease;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
.json-details-container {
|
|
516
|
+
padding: 20px;
|
|
517
|
+
border-radius: 8px;
|
|
518
|
+
text-align: left;
|
|
519
|
+
overflow-x: auto;
|
|
520
|
+
font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;
|
|
521
|
+
font-size: 0.9rem;
|
|
522
|
+
border: 1px solid;
|
|
523
|
+
transition:
|
|
524
|
+
background-color 0.3s ease,
|
|
525
|
+
color 0.3s ease,
|
|
526
|
+
border-color 0.3s ease;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
.json-details-container pre {
|
|
530
|
+
margin: 0;
|
|
531
|
+
white-space: pre-wrap;
|
|
532
|
+
word-break: break-all;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
.json-details-container code {
|
|
536
|
+
display: block;
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
body {
|
|
540
|
+
background-color: #f8fafc;
|
|
541
|
+
color: #1f2937;
|
|
542
|
+
}
|
|
543
|
+
.error-container {
|
|
544
|
+
background-color: #ffffff;
|
|
545
|
+
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08);
|
|
546
|
+
}
|
|
547
|
+
.status-code {
|
|
548
|
+
color: #dc2626;
|
|
549
|
+
}
|
|
550
|
+
.status-text {
|
|
551
|
+
color: #1f2937;
|
|
552
|
+
}
|
|
553
|
+
.error-message {
|
|
554
|
+
color: #4b5563;
|
|
555
|
+
}
|
|
556
|
+
.json-details-container {
|
|
557
|
+
background-color: #f0f4f8;
|
|
558
|
+
color: #374151;
|
|
559
|
+
border-color: #d1d5db;
|
|
560
|
+
}
|
|
561
|
+
.json-details-container p {
|
|
562
|
+
color: #6b7280;
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
@media (prefers-color-scheme: dark) {
|
|
566
|
+
body {
|
|
567
|
+
background-color: #2d3748;
|
|
568
|
+
color: #e2e8f0;
|
|
569
|
+
}
|
|
570
|
+
.error-container {
|
|
571
|
+
background-color: #1a202c;
|
|
572
|
+
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
|
|
573
|
+
}
|
|
574
|
+
.status-code {
|
|
575
|
+
color: #f56565;
|
|
576
|
+
}
|
|
577
|
+
.status-text {
|
|
578
|
+
color: #cbd5e1;
|
|
579
|
+
}
|
|
580
|
+
.error-message {
|
|
581
|
+
color: #a0aec0;
|
|
582
|
+
}
|
|
583
|
+
.json-details-container {
|
|
584
|
+
background-color: #2d3748;
|
|
585
|
+
color: #e2e8f0;
|
|
586
|
+
border-color: #4a5568;
|
|
587
|
+
}
|
|
588
|
+
.json-details-container p {
|
|
589
|
+
color: #a0aec0;
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
.footer {
|
|
594
|
+
display: flex;
|
|
595
|
+
gap: 0.25rem;
|
|
596
|
+
font-size: 0.6em;
|
|
597
|
+
justify-content: flex-end;
|
|
598
|
+
align-items: center;
|
|
599
|
+
margin-top: 12px;
|
|
600
|
+
opacity: 0.5;
|
|
601
|
+
transition: 0.25s ease-in-out;
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
.footer img {
|
|
605
|
+
filter: grayscale(0.5);
|
|
606
|
+
transition: 0.25s ease-in-out;
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
.footer:hover {
|
|
610
|
+
opacity: 1;
|
|
611
|
+
}
|
|
612
|
+
.footer:hover img {
|
|
613
|
+
filter: grayscale(0);
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
@media (max-width: 768px) {
|
|
617
|
+
body {
|
|
618
|
+
padding: 15px;
|
|
619
|
+
}
|
|
620
|
+
.error-container {
|
|
621
|
+
padding: 32px;
|
|
622
|
+
}
|
|
623
|
+
.status-code {
|
|
624
|
+
font-size: 4rem;
|
|
625
|
+
}
|
|
626
|
+
.status-text {
|
|
627
|
+
font-size: 1.8rem;
|
|
628
|
+
}
|
|
629
|
+
.error-message {
|
|
630
|
+
font-size: 1.1rem;
|
|
631
|
+
margin-bottom: 30px;
|
|
632
|
+
}
|
|
633
|
+
.json-details-container {
|
|
634
|
+
font-size: 0.85rem;
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
@media (max-width: 480px) {
|
|
639
|
+
body {
|
|
640
|
+
padding: 10px;
|
|
641
|
+
}
|
|
642
|
+
.error-container {
|
|
643
|
+
padding: 24px;
|
|
644
|
+
border-radius: 8px;
|
|
645
|
+
}
|
|
646
|
+
.status-code {
|
|
647
|
+
font-size: 3rem;
|
|
648
|
+
}
|
|
649
|
+
.status-text {
|
|
650
|
+
font-size: 1.5rem;
|
|
651
|
+
margin-bottom: 20px;
|
|
652
|
+
}
|
|
653
|
+
.error-message {
|
|
654
|
+
font-size: 1rem;
|
|
655
|
+
margin-bottom: 25px;
|
|
656
|
+
}
|
|
657
|
+
.json-details-container {
|
|
658
|
+
padding: 15px;
|
|
659
|
+
font-size: 0.8rem;
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
</style>
|
|
663
|
+
</head>
|
|
664
|
+
<body>
|
|
665
|
+
<div class="error-container">
|
|
666
|
+
<div id="statusCode" class="status-code">${icon} ${statusCode}</div>
|
|
667
|
+
|
|
668
|
+
<div id="statusText" class="status-text">${statusMessage}</div>
|
|
669
|
+
|
|
670
|
+
<p id="errorMessage" class="error-message">${message}</p>
|
|
671
|
+
|
|
672
|
+
<!-- prettier-ignore -->
|
|
673
|
+
<div class="json-details-container"style="display: ${details ? "block" : "none"};">
|
|
674
|
+
<p class="text-sm">Technical Details:</p>
|
|
675
|
+
<pre><code id="jsonDetails">${details}</code></pre>
|
|
676
|
+
</div>
|
|
677
|
+
<div class="footer">
|
|
678
|
+
Powered by
|
|
679
|
+
<a href="${link}" target="_blank">
|
|
680
|
+
<img height="20" alt="%{poweredBy}" src="${image}" />
|
|
681
|
+
</a>
|
|
682
|
+
v${version}
|
|
683
|
+
</div>
|
|
684
|
+
</div>
|
|
685
|
+
</body>
|
|
686
|
+
</html>
|
|
687
|
+
`;
|
|
688
|
+
}
|
|
689
|
+
|
|
338
690
|
//#endregion
|
|
339
691
|
//#region packages/event-http/src/errors/error-renderer.ts
|
|
340
|
-
|
|
692
|
+
let framework = {
|
|
693
|
+
version: "0.6.1",
|
|
694
|
+
poweredBy: `wooksjs`,
|
|
695
|
+
link: `https://wooks.moost.org/`,
|
|
696
|
+
image: `https://wooks.moost.org/wooks-full-logo.png`
|
|
697
|
+
};
|
|
341
698
|
var HttpErrorRenderer = class extends BaseHttpResponseRenderer {
|
|
699
|
+
constructor(opts) {
|
|
700
|
+
super();
|
|
701
|
+
this.opts = opts;
|
|
702
|
+
}
|
|
703
|
+
icons = {
|
|
704
|
+
401: typeof _403_tl_default === "function" ? _403_tl_default({}) : "",
|
|
705
|
+
403: typeof _403_tl_default === "function" ? _403_tl_default({}) : "",
|
|
706
|
+
404: typeof _404_tl_default === "function" ? _404_tl_default({}) : "",
|
|
707
|
+
500: typeof _500_tl_default === "function" ? _500_tl_default({}) : ""
|
|
708
|
+
};
|
|
709
|
+
static registerFramework(opts) {
|
|
710
|
+
framework = opts;
|
|
711
|
+
}
|
|
342
712
|
renderHtml(response) {
|
|
343
713
|
const data = response.body || {};
|
|
344
714
|
response.setContentType("text/html");
|
|
345
|
-
const
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
715
|
+
const hasDetails = Object.keys(data).length > 3;
|
|
716
|
+
const icon = data.statusCode >= 500 ? this.icons[500] : this.icons[data.statusCode] || "";
|
|
717
|
+
return typeof error_tl_default === "function" ? error_tl_default({
|
|
718
|
+
icon,
|
|
719
|
+
statusCode: data.statusCode,
|
|
720
|
+
statusMessage: httpStatusCodes[data.statusCode],
|
|
721
|
+
message: data.message,
|
|
722
|
+
details: hasDetails ? JSON.stringify(data, null, " ") : "",
|
|
723
|
+
version: (this.opts || framework).version,
|
|
724
|
+
poweredBy: (this.opts || framework).poweredBy,
|
|
725
|
+
link: (this.opts || framework).link,
|
|
726
|
+
image: (this.opts || framework).image
|
|
727
|
+
}) : JSON.stringify(data, null, " ");
|
|
356
728
|
}
|
|
357
729
|
renderText(response) {
|
|
358
730
|
const data = response.body || {};
|
|
@@ -362,11 +734,11 @@ var HttpErrorRenderer = class extends BaseHttpResponseRenderer {
|
|
|
362
734
|
"error",
|
|
363
735
|
"message"
|
|
364
736
|
].includes(key));
|
|
365
|
-
return `${data.statusCode} ${httpStatusCodes[data.statusCode]}\n${data.message}
|
|
737
|
+
return `${data.statusCode} ${httpStatusCodes[data.statusCode]}\n${data.message}\n\n${keys.length > 0 ? `${JSON.stringify({
|
|
366
738
|
...data,
|
|
367
|
-
statusCode:
|
|
368
|
-
message:
|
|
369
|
-
error:
|
|
739
|
+
statusCode: void 0,
|
|
740
|
+
message: void 0,
|
|
741
|
+
error: void 0
|
|
370
742
|
}, null, " ")}` : ""}`;
|
|
371
743
|
}
|
|
372
744
|
renderJson(response) {
|
|
@@ -377,15 +749,15 @@ var HttpErrorRenderer = class extends BaseHttpResponseRenderer {
|
|
|
377
749
|
"error",
|
|
378
750
|
"message"
|
|
379
751
|
].includes(key));
|
|
380
|
-
return `{"statusCode":${escapeQuotes(data.statusCode)}
|
|
752
|
+
return `{"statusCode":${escapeQuotes(data.statusCode)},"error":"${escapeQuotes(data.error)}","message":"${escapeQuotes(data.message)}"${keys.length > 0 ? `,${keys.map((k) => `"${escapeQuotes(k)}":${JSON.stringify(data[k])}`).join(",")}` : ""}}`;
|
|
381
753
|
}
|
|
382
754
|
render(response) {
|
|
383
755
|
const { acceptsJson, acceptsText, acceptsHtml } = useAccept();
|
|
384
756
|
response.status = response.body?.statusCode || 500;
|
|
385
757
|
if (acceptsJson()) return this.renderJson(response);
|
|
386
|
-
else if (acceptsHtml()) return this.renderHtml(response);
|
|
387
|
-
else if (acceptsText()) return this.renderText(response);
|
|
388
|
-
else return this.renderJson(response);
|
|
758
|
+
else if (acceptsHtml()) return this.renderHtml(response);
|
|
759
|
+
else if (acceptsText()) return this.renderText(response);
|
|
760
|
+
else return this.renderJson(response);
|
|
389
761
|
}
|
|
390
762
|
};
|
|
391
763
|
function escapeQuotes(s) {
|
|
@@ -426,8 +798,8 @@ var HttpError = class extends Error {
|
|
|
426
798
|
//#region packages/event-http/src/composables/request.ts
|
|
427
799
|
const xForwardedFor = "x-forwarded-for";
|
|
428
800
|
const DEFAULT_LIMITS = {
|
|
429
|
-
maxCompressed:
|
|
430
|
-
maxInflated:
|
|
801
|
+
maxCompressed: 1 * 1024 * 1024,
|
|
802
|
+
maxInflated: 10 * 1024 * 1024,
|
|
431
803
|
maxRatio: 100,
|
|
432
804
|
readTimeoutMs: 1e4
|
|
433
805
|
};
|
|
@@ -521,12 +893,12 @@ function useRequest() {
|
|
|
521
893
|
const reqId = (0, __wooksjs_event_core.useEventId)().getId;
|
|
522
894
|
const forwardedIp = () => init("forwardedIp", () => {
|
|
523
895
|
if (typeof req.headers[xForwardedFor] === "string" && req.headers[xForwardedFor]) return req.headers[xForwardedFor].split(",").shift()?.trim();
|
|
524
|
-
else return "";
|
|
896
|
+
else return "";
|
|
525
897
|
});
|
|
526
898
|
const remoteIp = () => init("remoteIp", () => req.socket.remoteAddress || req.connection.remoteAddress || "");
|
|
527
899
|
function getIp(options) {
|
|
528
900
|
if (options?.trustProxy) return forwardedIp() || getIp();
|
|
529
|
-
else return remoteIp();
|
|
901
|
+
else return remoteIp();
|
|
530
902
|
}
|
|
531
903
|
const getIpList = () => init("ipList", () => ({
|
|
532
904
|
remoteIp: req.socket.remoteAddress || req.connection.remoteAddress || "",
|
|
@@ -707,7 +1079,7 @@ function useAuthorization() {
|
|
|
707
1079
|
function renderCacheControl(data) {
|
|
708
1080
|
let attrs = "";
|
|
709
1081
|
for (const [a, v] of Object.entries(data)) {
|
|
710
|
-
if (v ===
|
|
1082
|
+
if (v === void 0) continue;
|
|
711
1083
|
const func = cacheControlFunc[a];
|
|
712
1084
|
if (typeof func === "function") {
|
|
713
1085
|
const val = func(v);
|
|
@@ -950,14 +1322,14 @@ var BaseHttpResponse = class {
|
|
|
950
1322
|
});
|
|
951
1323
|
stream$1.on("close", () => {
|
|
952
1324
|
stream$1.destroy();
|
|
953
|
-
resolve(
|
|
1325
|
+
resolve(void 0);
|
|
954
1326
|
});
|
|
955
1327
|
stream$1.pipe(res);
|
|
956
1328
|
});
|
|
957
1329
|
} else if (globalThis.Response && this.body instanceof Response) {
|
|
958
1330
|
this.mergeFetchStatus(this.body.status);
|
|
959
1331
|
if (method === "HEAD") res.end();
|
|
960
|
-
else {
|
|
1332
|
+
else {
|
|
961
1333
|
const additionalHeaders = {};
|
|
962
1334
|
if (this.body.headers.get("content-length")) additionalHeaders["content-length"] = this.body.headers.get("content-length");
|
|
963
1335
|
if (this.body.headers.get("content-type")) additionalHeaders["content-type"] = this.body.headers.get("content-type");
|
|
@@ -994,11 +1366,11 @@ function createWooksResponder(renderer = new BaseHttpResponseRenderer(), errorRe
|
|
|
994
1366
|
const r = new BaseHttpResponse(errorRenderer);
|
|
995
1367
|
let httpError;
|
|
996
1368
|
if (data instanceof HttpError) httpError = data;
|
|
997
|
-
else httpError = new HttpError(500, data.message);
|
|
1369
|
+
else httpError = new HttpError(500, data.message);
|
|
998
1370
|
r.setBody(httpError.body);
|
|
999
1371
|
return r;
|
|
1000
1372
|
} else if (data instanceof BaseHttpResponse) return data;
|
|
1001
|
-
else return new BaseHttpResponse(renderer).setBody(data);
|
|
1373
|
+
else return new BaseHttpResponse(renderer).setBody(data);
|
|
1002
1374
|
}
|
|
1003
1375
|
return {
|
|
1004
1376
|
createResponse,
|
|
@@ -1013,7 +1385,7 @@ var WooksHttp = class extends wooks.WooksAdapterBase {
|
|
|
1013
1385
|
constructor(opts, wooks$1) {
|
|
1014
1386
|
super(wooks$1, opts?.logger, opts?.router);
|
|
1015
1387
|
this.opts = opts;
|
|
1016
|
-
this.logger = opts?.logger || this.getLogger(
|
|
1388
|
+
this.logger = opts?.logger || this.getLogger(`[96m[wooks-http]`);
|
|
1017
1389
|
}
|
|
1018
1390
|
all(path, handler) {
|
|
1019
1391
|
return this.on("*", path, handler);
|
|
@@ -1051,7 +1423,7 @@ var WooksHttp = class extends wooks.WooksAdapterBase {
|
|
|
1051
1423
|
backlog,
|
|
1052
1424
|
listeningListener
|
|
1053
1425
|
];
|
|
1054
|
-
const ui = args.indexOf(
|
|
1426
|
+
const ui = args.indexOf(void 0);
|
|
1055
1427
|
if (ui >= 0) args = args.slice(0, ui);
|
|
1056
1428
|
server.listen(...args);
|
|
1057
1429
|
});
|
|
@@ -1093,7 +1465,7 @@ var WooksHttp = class extends wooks.WooksAdapterBase {
|
|
|
1093
1465
|
}
|
|
1094
1466
|
responder = createWooksResponder();
|
|
1095
1467
|
respond(data) {
|
|
1096
|
-
|
|
1468
|
+
this.responder.respond(data)?.catch((e) => {
|
|
1097
1469
|
this.logger.error("Uncaught response exception", e);
|
|
1098
1470
|
});
|
|
1099
1471
|
}
|
|
@@ -1124,7 +1496,7 @@ var WooksHttp = class extends wooks.WooksAdapterBase {
|
|
|
1124
1496
|
this.respond(error);
|
|
1125
1497
|
return error;
|
|
1126
1498
|
}
|
|
1127
|
-
else {
|
|
1499
|
+
else {
|
|
1128
1500
|
this.logger.debug(`404 Not found (${req.method})${req.url}`);
|
|
1129
1501
|
const error = new HttpError(404);
|
|
1130
1502
|
this.respond(error);
|
|
@@ -1152,47 +1524,53 @@ else {
|
|
|
1152
1524
|
}
|
|
1153
1525
|
}
|
|
1154
1526
|
};
|
|
1527
|
+
/**
|
|
1528
|
+
* Factory for WooksHttp App
|
|
1529
|
+
* @param opts TWooksHttpOptions
|
|
1530
|
+
* @param wooks Wooks | WooksAdapterBase
|
|
1531
|
+
* @returns WooksHttp
|
|
1532
|
+
*/
|
|
1155
1533
|
function createHttpApp(opts, wooks$1) {
|
|
1156
1534
|
return new WooksHttp(opts, wooks$1);
|
|
1157
1535
|
}
|
|
1158
1536
|
|
|
1159
1537
|
//#endregion
|
|
1160
|
-
exports.BaseHttpResponse = BaseHttpResponse
|
|
1161
|
-
exports.BaseHttpResponseRenderer = BaseHttpResponseRenderer
|
|
1162
|
-
exports.DEFAULT_LIMITS = DEFAULT_LIMITS
|
|
1163
|
-
exports.EHttpStatusCode = EHttpStatusCode
|
|
1164
|
-
exports.HttpError = HttpError
|
|
1165
|
-
exports.HttpErrorRenderer = HttpErrorRenderer
|
|
1166
|
-
exports.WooksHttp = WooksHttp
|
|
1167
|
-
exports.WooksURLSearchParams = WooksURLSearchParams
|
|
1168
|
-
exports.createHttpApp = createHttpApp
|
|
1169
|
-
exports.createHttpContext = createHttpContext
|
|
1170
|
-
exports.createWooksResponder = createWooksResponder
|
|
1171
|
-
exports.httpStatusCodes = httpStatusCodes
|
|
1172
|
-
exports.renderCacheControl = renderCacheControl
|
|
1173
|
-
exports.useAccept = useAccept
|
|
1174
|
-
exports.useAuthorization = useAuthorization
|
|
1175
|
-
exports.useCookies = useCookies
|
|
1538
|
+
exports.BaseHttpResponse = BaseHttpResponse;
|
|
1539
|
+
exports.BaseHttpResponseRenderer = BaseHttpResponseRenderer;
|
|
1540
|
+
exports.DEFAULT_LIMITS = DEFAULT_LIMITS;
|
|
1541
|
+
exports.EHttpStatusCode = EHttpStatusCode;
|
|
1542
|
+
exports.HttpError = HttpError;
|
|
1543
|
+
exports.HttpErrorRenderer = HttpErrorRenderer;
|
|
1544
|
+
exports.WooksHttp = WooksHttp;
|
|
1545
|
+
exports.WooksURLSearchParams = WooksURLSearchParams;
|
|
1546
|
+
exports.createHttpApp = createHttpApp;
|
|
1547
|
+
exports.createHttpContext = createHttpContext;
|
|
1548
|
+
exports.createWooksResponder = createWooksResponder;
|
|
1549
|
+
exports.httpStatusCodes = httpStatusCodes;
|
|
1550
|
+
exports.renderCacheControl = renderCacheControl;
|
|
1551
|
+
exports.useAccept = useAccept;
|
|
1552
|
+
exports.useAuthorization = useAuthorization;
|
|
1553
|
+
exports.useCookies = useCookies;
|
|
1176
1554
|
Object.defineProperty(exports, 'useEventLogger', {
|
|
1177
1555
|
enumerable: true,
|
|
1178
1556
|
get: function () {
|
|
1179
1557
|
return __wooksjs_event_core.useEventLogger;
|
|
1180
1558
|
}
|
|
1181
1559
|
});
|
|
1182
|
-
exports.useHeaders = useHeaders
|
|
1183
|
-
exports.useHttpContext = useHttpContext
|
|
1184
|
-
exports.useRequest = useRequest
|
|
1185
|
-
exports.useResponse = useResponse
|
|
1560
|
+
exports.useHeaders = useHeaders;
|
|
1561
|
+
exports.useHttpContext = useHttpContext;
|
|
1562
|
+
exports.useRequest = useRequest;
|
|
1563
|
+
exports.useResponse = useResponse;
|
|
1186
1564
|
Object.defineProperty(exports, 'useRouteParams', {
|
|
1187
1565
|
enumerable: true,
|
|
1188
1566
|
get: function () {
|
|
1189
1567
|
return __wooksjs_event_core.useRouteParams;
|
|
1190
1568
|
}
|
|
1191
1569
|
});
|
|
1192
|
-
exports.useSearchParams = useSearchParams
|
|
1193
|
-
exports.useSetCacheControl = useSetCacheControl
|
|
1194
|
-
exports.useSetCookie = useSetCookie
|
|
1195
|
-
exports.useSetCookies = useSetCookies
|
|
1196
|
-
exports.useSetHeader = useSetHeader
|
|
1197
|
-
exports.useSetHeaders = useSetHeaders
|
|
1198
|
-
exports.useStatus = useStatus
|
|
1570
|
+
exports.useSearchParams = useSearchParams;
|
|
1571
|
+
exports.useSetCacheControl = useSetCacheControl;
|
|
1572
|
+
exports.useSetCookie = useSetCookie;
|
|
1573
|
+
exports.useSetCookies = useSetCookies;
|
|
1574
|
+
exports.useSetHeader = useSetHeader;
|
|
1575
|
+
exports.useSetHeaders = useSetHeaders;
|
|
1576
|
+
exports.useStatus = useStatus;
|