@rpcbase/server 0.445.0 → 0.447.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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"applyRouteLoaders.d.ts","sourceRoot":"","sources":["../src/applyRouteLoaders.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,OAAO,EAAC,MAAM,SAAS,CAAA;AAC/B,OAAO,EACL,oBAAoB,EAMrB,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"applyRouteLoaders.d.ts","sourceRoot":"","sources":["../src/applyRouteLoaders.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,OAAO,EAAC,MAAM,SAAS,CAAA;AAC/B,OAAO,EACL,oBAAoB,EAMrB,MAAM,iBAAiB,CAAA;AAoExB,wBAAsB,iBAAiB,CACrC,GAAG,EAAE,OAAO,EACZ,UAAU,EAAE,GAAG,EAAE,GAChB,OAAO,CAAC,oBAAoB,CAAC,CAqH/B"}
|
package/dist/index.js
CHANGED
|
@@ -362,6 +362,15 @@ function getShortCircuitMatches(routes) {
|
|
|
362
362
|
route
|
|
363
363
|
};
|
|
364
364
|
}
|
|
365
|
+
const NOT_FOUND_STATUS = 404;
|
|
366
|
+
const getErrorStatus = (error) => {
|
|
367
|
+
if (!error) return void 0;
|
|
368
|
+
const candidate = error?.reason ?? error;
|
|
369
|
+
if (typeof candidate?.status === "number") return candidate.status;
|
|
370
|
+
if (typeof candidate?.statusCode === "number") return candidate.statusCode;
|
|
371
|
+
if (typeof candidate?.response?.status === "number") return candidate.response.status;
|
|
372
|
+
return void 0;
|
|
373
|
+
};
|
|
365
374
|
async function applyRouteLoaders(req, dataRoutes) {
|
|
366
375
|
const baseUrl = `${req.protocol}://${req.get("host")}`;
|
|
367
376
|
const url = new URL(req.originalUrl, baseUrl);
|
|
@@ -418,6 +427,8 @@ async function applyRouteLoaders(req, dataRoutes) {
|
|
|
418
427
|
);
|
|
419
428
|
const loaderData = {};
|
|
420
429
|
let errors = null;
|
|
430
|
+
let hasNotFoundError = false;
|
|
431
|
+
let hasNonNotFoundError = false;
|
|
421
432
|
for (const result of loaderPromisesResults) {
|
|
422
433
|
if (result.status === "fulfilled") {
|
|
423
434
|
if (result.value) {
|
|
@@ -431,16 +442,32 @@ async function applyRouteLoaders(req, dataRoutes) {
|
|
|
431
442
|
if (!errors) {
|
|
432
443
|
errors = {};
|
|
433
444
|
}
|
|
445
|
+
const status = getErrorStatus(result.reason);
|
|
446
|
+
if (status === NOT_FOUND_STATUS) {
|
|
447
|
+
hasNotFoundError = true;
|
|
448
|
+
} else {
|
|
449
|
+
hasNonNotFoundError = true;
|
|
450
|
+
}
|
|
434
451
|
errors[id] = result.reason;
|
|
435
452
|
}
|
|
436
453
|
}
|
|
454
|
+
let statusCode = 200;
|
|
455
|
+
if (errors) {
|
|
456
|
+
if (hasNonNotFoundError) {
|
|
457
|
+
statusCode = 500;
|
|
458
|
+
} else if (hasNotFoundError) {
|
|
459
|
+
statusCode = NOT_FOUND_STATUS;
|
|
460
|
+
} else {
|
|
461
|
+
statusCode = 500;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
437
464
|
return {
|
|
438
465
|
...baseContext,
|
|
439
466
|
matches,
|
|
440
467
|
loaderData,
|
|
441
468
|
actionData: null,
|
|
442
469
|
errors,
|
|
443
|
-
statusCode
|
|
470
|
+
statusCode
|
|
444
471
|
};
|
|
445
472
|
}
|
|
446
473
|
async function renderSSR(req, dataRoutes) {
|
|
@@ -470,7 +497,7 @@ async function renderSSR(req, dataRoutes) {
|
|
|
470
497
|
}
|
|
471
498
|
) });
|
|
472
499
|
const isMatched = routerContext.matches.length > 0;
|
|
473
|
-
return { element, isMatched };
|
|
500
|
+
return { element, isMatched, statusCode: routerContext.statusCode ?? (routerContext.errors ? 500 : 200) };
|
|
474
501
|
}
|
|
475
502
|
const ABORT_DELAY_MS = 1e4;
|
|
476
503
|
const APP_HTML_PLACEHOLDER = "<!--app-html-->";
|
|
@@ -591,7 +618,7 @@ const ssrMiddleware = ({
|
|
|
591
618
|
htmlStart = templateStart;
|
|
592
619
|
}
|
|
593
620
|
htmlEnd = template.slice(placeholderIndex + APP_HTML_PLACEHOLDER.length);
|
|
594
|
-
const { element, isMatched } = await renderSSR(req, dataRoutes);
|
|
621
|
+
const { element, isMatched, statusCode } = await renderSSR(req, dataRoutes);
|
|
595
622
|
if (!isMatched) {
|
|
596
623
|
next();
|
|
597
624
|
return;
|
|
@@ -624,7 +651,8 @@ const ssrMiddleware = ({
|
|
|
624
651
|
return;
|
|
625
652
|
}
|
|
626
653
|
responseCommitted = true;
|
|
627
|
-
|
|
654
|
+
const responseStatus = didError ? 500 : statusCode || 200;
|
|
655
|
+
res.status(responseStatus);
|
|
628
656
|
res.set({ "Content-Type": "text/html" });
|
|
629
657
|
const transformStream = new Transform({
|
|
630
658
|
transform(chunk, encoding, callback) {
|
package/dist/renderSSR.d.ts
CHANGED
package/dist/renderSSR.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderSSR.d.ts","sourceRoot":"","sources":["../src/renderSSR.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAA;AAClC,OAAO,EAAE,SAAS,EAAc,MAAM,OAAO,CAAA;AAC7C,OAAO,EAGL,aAAa,EACd,MAAM,iBAAiB,CAAA;AAOxB,wBAAsB,SAAS,CAC7B,GAAG,EAAE,OAAO,CAAC,OAAO,EACpB,UAAU,EAAE,aAAa,CAAC,YAAY,CAAC,GACtC,OAAO,CAAC;IAAC,OAAO,EAAE,SAAS,CAAC;IAAC,SAAS,EAAE,OAAO,CAAA;CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"renderSSR.d.ts","sourceRoot":"","sources":["../src/renderSSR.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAA;AAClC,OAAO,EAAE,SAAS,EAAc,MAAM,OAAO,CAAA;AAC7C,OAAO,EAGL,aAAa,EACd,MAAM,iBAAiB,CAAA;AAOxB,wBAAsB,SAAS,CAC7B,GAAG,EAAE,OAAO,CAAC,OAAO,EACpB,UAAU,EAAE,aAAa,CAAC,YAAY,CAAC,GACtC,OAAO,CAAC;IAAC,OAAO,EAAE,SAAS,CAAC;IAAC,SAAS,EAAE,OAAO,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAC,CAAC,CAuCvE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ssrMiddleware.d.ts","sourceRoot":"","sources":["../src/ssrMiddleware.ts"],"names":[],"mappings":"AAKA,OAAO,EAAwE,KAAK,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AACjI,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AACnC,OAAO,EAA6B,KAAK,aAAa,EAAE,MAAM,OAAO,CAAA;AAErE,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAKzD,KAAK,aAAa,GAAG,OAAO,CAAC,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC,CAAC;AAyG9D,eAAO,MAAM,aAAa,GAAI,yEAK3B;IACD,YAAY,EAAE,aAAa,CAAC;IAC5B,UAAU,EAAE,aAAa,CAAC,YAAY,CAAC,CAAC;IACxC,mBAAmB,CAAC,EAAE,aAAa,CAAC;QAAE,KAAK,CAAC,EAAE,oBAAoB,CAAA;KAAE,CAAC,CAAC;IACtE,mBAAmB,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;CAChF,MAAW,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,
|
|
1
|
+
{"version":3,"file":"ssrMiddleware.d.ts","sourceRoot":"","sources":["../src/ssrMiddleware.ts"],"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