Skip to content

Commit be9a028

Browse files
committed
Add negotiated error pages and use them
Introduce a self-contained, content-negotiated error page renderer (HTML/JSON/text) in crates/nexide/src/server/error_page.rs and tests. Integrate it into the server by wiring it into next_bridge and static_assets so dispatch failures and handler errors return polished responses (with optional machine-readable detail) instead of plain text. Update module registration in server/mod.rs. Improve runtime polyfill cjs_loader.js to track a moduleStack so dynamic imports without an explicit referrer resolve relative to the calling module, and add a test for that behavior in crates/nexide/tests/cjs_loader.rs. Finally, bump workspace version to 0.1.15 in Cargo.toml and update Cargo.lock accordingly.
1 parent 793debf commit be9a028

8 files changed

Lines changed: 440 additions & 34 deletions

File tree

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ members = [
77
]
88

99
[workspace.package]
10-
version = "0.1.14"
10+
version = "0.1.15"
1111
edition = "2024"
1212
license = "MIT OR Apache-2.0"
1313
publish = false

crates/nexide/runtime/polyfills/cjs_loader.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
const ops = Nexide.core.ops;
1616
const cache = new Map();
17+
const moduleStack = [];
1718

1819
function dirnameOf(spec) {
1920
if (typeof spec !== "string" || spec.length === 0) return "";
@@ -37,7 +38,15 @@
3738
source +
3839
"\n})\n//# sourceURL=" +
3940
specifier;
40-
return (0, eval)(wrapper);
41+
const fn = (0, eval)(wrapper);
42+
return function (exports, require, module, __filename, __dirname) {
43+
moduleStack.push(specifier);
44+
try {
45+
return fn(exports, require, module, __filename, __dirname);
46+
} finally {
47+
moduleStack.pop();
48+
}
49+
};
4150
}
4251

4352
function makeRequire(parent) {
@@ -117,9 +126,14 @@
117126
}
118127

119128
function dynamicImport(specifier, referrer) {
120-
const parent = (typeof referrer === "string" && referrer.length > 0)
121-
? referrer
122-
: ops.op_cjs_root_parent();
129+
let parent;
130+
if (typeof referrer === "string" && referrer.length > 0) {
131+
parent = referrer;
132+
} else if (moduleStack.length > 0) {
133+
parent = moduleStack[moduleStack.length - 1];
134+
} else {
135+
parent = ops.op_cjs_root_parent();
136+
}
123137
const exports = loadModule(parent, specifier);
124138
return buildNamespace(exports);
125139
}

0 commit comments

Comments
 (0)