@ereo/server 0.2.13 → 0.2.14
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/bun-server.d.ts +9 -0
- package/dist/bun-server.d.ts.map +1 -1
- package/dist/index.js +97 -1
- package/package.json +5 -5
package/dist/bun-server.d.ts
CHANGED
|
@@ -178,6 +178,15 @@ export declare class BunServer {
|
|
|
178
178
|
* Escape HTML special characters.
|
|
179
179
|
*/
|
|
180
180
|
private escapeHtml;
|
|
181
|
+
/**
|
|
182
|
+
* Find the nearest _error route for a given match.
|
|
183
|
+
* Searches from the matched route's directory upward to root.
|
|
184
|
+
*/
|
|
185
|
+
private findErrorBoundary;
|
|
186
|
+
/**
|
|
187
|
+
* Render an error page using the nearest _error boundary component.
|
|
188
|
+
*/
|
|
189
|
+
private renderErrorBoundaryPage;
|
|
181
190
|
/**
|
|
182
191
|
* Handle errors.
|
|
183
192
|
*/
|
package/dist/bun-server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bun-server.d.ts","sourceRoot":"","sources":["../src/bun-server.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,KAAK,CAAC;AAClC,OAAO,KAAK,EAAmE,iBAAiB,EAA0C,MAAM,YAAY,CAAC;AAC7J,OAAO,EAAiC,OAAO,EAAiB,MAAM,YAAY,CAAC;AACnF,OAAO,EAAE,UAAU,EAAwD,MAAM,cAAc,CAAC;AAChG,OAAO,EAIL,IAAI,EACJ,eAAe,EAChB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAe,KAAK,aAAa,EAAE,MAAM,UAAU,CAAC;AAC3D,OAAO,EAA+C,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAgE9F;;;;;;GAMG;AACH,MAAM,MAAM,gBAAgB,GAAG,WAAW,GAAG,QAAQ,CAAC;AAEtD;;GAEG;AACH,MAAM,WAAW,aA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B;IA8BxB;;;;OAIG;IACH,OAAO,CAAC,iBAAiB;IA4CzB;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAqBzB;;OAEG;IACH,OAAO,CAAC,UAAU;IASlB;;;OAGG;YACW,iBAAiB;IAmD/B;;OAEG;YACW,uBAAuB;IA2DrC;;OAEG;IACH,OAAO,CAAC,WAAW;IA0CnB;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAmCvC;;OAEG;IACH,IAAI,IAAI,IAAI;IAOZ;;OAEG;IACG,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAQ7B;;OAEG;IACH,SAAS,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,IAAI;IAInC;;OAEG;IACH,OAAO,IAAI;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,OAAO,CAAA;KAAE;CAOpE;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,OAAO,CAAC,EAAE,aAAa,GAAG,SAAS,CAE/D;AAED;;GAEG;AACH,wBAAsB,KAAK,CAAC,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,SAAS,CAAC,CAIvE"}
|
package/dist/index.js
CHANGED
|
@@ -927,7 +927,22 @@ class BunServer {
|
|
|
927
927
|
for (const layout of layouts) {
|
|
928
928
|
loaderPromises.push(layout.module?.loader ? Promise.resolve(layout.module.loader(loaderArgs)) : Promise.resolve(null));
|
|
929
929
|
}
|
|
930
|
-
|
|
930
|
+
let loaderResults;
|
|
931
|
+
try {
|
|
932
|
+
loaderResults = await Promise.all(loaderPromises);
|
|
933
|
+
} catch (thrownError) {
|
|
934
|
+
if (thrownError instanceof Response) {
|
|
935
|
+
if (thrownError.status >= 300 && thrownError.status < 400) {
|
|
936
|
+
return thrownError;
|
|
937
|
+
}
|
|
938
|
+
const errorRoute = await this.findErrorBoundary(match);
|
|
939
|
+
if (errorRoute) {
|
|
940
|
+
return this.renderErrorBoundaryPage(request, match, context, thrownError, errorRoute);
|
|
941
|
+
}
|
|
942
|
+
return thrownError;
|
|
943
|
+
}
|
|
944
|
+
throw thrownError;
|
|
945
|
+
}
|
|
931
946
|
const loaderData = loaderResults[0];
|
|
932
947
|
if (loaderData instanceof Response) {
|
|
933
948
|
return loaderData;
|
|
@@ -1401,6 +1416,87 @@ class BunServer {
|
|
|
1401
1416
|
escapeHtml(str) {
|
|
1402
1417
|
return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
1403
1418
|
}
|
|
1419
|
+
async findErrorBoundary(match) {
|
|
1420
|
+
if (!this.router || typeof this.router.getRoutes !== "function")
|
|
1421
|
+
return null;
|
|
1422
|
+
const flattenRoutes = (routes) => {
|
|
1423
|
+
const result = [];
|
|
1424
|
+
for (const route of routes) {
|
|
1425
|
+
result.push(route);
|
|
1426
|
+
if (route.children) {
|
|
1427
|
+
result.push(...flattenRoutes(route.children));
|
|
1428
|
+
}
|
|
1429
|
+
}
|
|
1430
|
+
return result;
|
|
1431
|
+
};
|
|
1432
|
+
const allRoutes = flattenRoutes(this.router.getRoutes());
|
|
1433
|
+
const matchPath = match.route.path;
|
|
1434
|
+
const segments = matchPath.split("/").filter(Boolean);
|
|
1435
|
+
const candidates = [];
|
|
1436
|
+
for (let i = segments.length;i >= 0; i--) {
|
|
1437
|
+
const prefix = "/" + segments.slice(0, i).join("/");
|
|
1438
|
+
candidates.push(prefix === "/" ? "/_error" : prefix + "/_error");
|
|
1439
|
+
}
|
|
1440
|
+
for (const candidate of candidates) {
|
|
1441
|
+
const errorRoute = allRoutes.find((r) => {
|
|
1442
|
+
if (r.path === candidate)
|
|
1443
|
+
return true;
|
|
1444
|
+
if (r.file?.includes("_error")) {
|
|
1445
|
+
const normalizedCandidate = candidate.replace("/_error", "") || "/";
|
|
1446
|
+
const normalizedRoutePath = r.path.replace("/_error", "") || "/";
|
|
1447
|
+
return normalizedRoutePath === normalizedCandidate;
|
|
1448
|
+
}
|
|
1449
|
+
return false;
|
|
1450
|
+
});
|
|
1451
|
+
if (errorRoute) {
|
|
1452
|
+
if (typeof this.router.loadModule === "function") {
|
|
1453
|
+
await this.router.loadModule(errorRoute);
|
|
1454
|
+
}
|
|
1455
|
+
if (errorRoute.module?.default) {
|
|
1456
|
+
return errorRoute;
|
|
1457
|
+
}
|
|
1458
|
+
}
|
|
1459
|
+
}
|
|
1460
|
+
return null;
|
|
1461
|
+
}
|
|
1462
|
+
async renderErrorBoundaryPage(request, match, context, errorResponse, errorRoute) {
|
|
1463
|
+
const url = new URL(request.url);
|
|
1464
|
+
const ErrorComponent = errorRoute.module.default;
|
|
1465
|
+
const bodyText = await errorResponse.clone().text();
|
|
1466
|
+
const routeError = Object.assign(new Error(bodyText || errorResponse.statusText), {
|
|
1467
|
+
status: errorResponse.status,
|
|
1468
|
+
statusText: errorResponse.statusText || (errorResponse.status === 404 ? "Not Found" : "Error"),
|
|
1469
|
+
data: bodyText
|
|
1470
|
+
});
|
|
1471
|
+
let element = createElement(ErrorComponent, { error: routeError });
|
|
1472
|
+
element = createElement(EreoProvider, {
|
|
1473
|
+
loaderData: null,
|
|
1474
|
+
actionData: undefined,
|
|
1475
|
+
params: match.params,
|
|
1476
|
+
location: { pathname: url.pathname, search: url.search, hash: "", state: null, key: "ssr" },
|
|
1477
|
+
error: routeError,
|
|
1478
|
+
children: element
|
|
1479
|
+
});
|
|
1480
|
+
const layouts = match.layouts || [];
|
|
1481
|
+
for (let i = layouts.length - 1;i >= 0; i--) {
|
|
1482
|
+
const layout = layouts[i];
|
|
1483
|
+
if (layout.module?.default) {
|
|
1484
|
+
const LayoutComponent = layout.module.default;
|
|
1485
|
+
const childElement = element;
|
|
1486
|
+
element = createElement(OutletProvider, { element: childElement }, createElement(LayoutComponent, {
|
|
1487
|
+
loaderData: null,
|
|
1488
|
+
params: match.params,
|
|
1489
|
+
children: childElement
|
|
1490
|
+
}));
|
|
1491
|
+
}
|
|
1492
|
+
}
|
|
1493
|
+
const { renderToString: reactRenderToString } = await import("react-dom/server");
|
|
1494
|
+
const content = reactRenderToString(element);
|
|
1495
|
+
return new Response(content, {
|
|
1496
|
+
status: errorResponse.status,
|
|
1497
|
+
headers: { "Content-Type": "text/html; charset=utf-8" }
|
|
1498
|
+
});
|
|
1499
|
+
}
|
|
1404
1500
|
handleError(error, context) {
|
|
1405
1501
|
if (error instanceof Response) {
|
|
1406
1502
|
return error;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ereo/server",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.14",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Ereo Team",
|
|
6
6
|
"homepage": "https://ereojs.github.io/ereoJS",
|
|
@@ -32,10 +32,10 @@
|
|
|
32
32
|
"typecheck": "tsc --noEmit"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@ereo/core": "^0.2.
|
|
36
|
-
"@ereo/client": "^0.2.
|
|
37
|
-
"@ereo/router": "^0.2.
|
|
38
|
-
"@ereo/data": "^0.2.
|
|
35
|
+
"@ereo/core": "^0.2.14",
|
|
36
|
+
"@ereo/client": "^0.2.14",
|
|
37
|
+
"@ereo/router": "^0.2.14",
|
|
38
|
+
"@ereo/data": "^0.2.14"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/bun": "^1.1.0",
|