aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2021-11-15 15:47:28 -0800
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2021-11-15 15:47:28 -0800
commit4e775d275c33ae67d583732d2c3649dc89a0002d (patch)
treeda52afdf434a1022da731171b27008d79b49afb2
parent035f6fe5e1329868bc24c53a50df2e04d4b7bae0 (diff)
downloadbun-4e775d275c33ae67d583732d2c3649dc89a0002d.tar.gz
bun-4e775d275c33ae67d583732d2c3649dc89a0002d.tar.zst
bun-4e775d275c33ae67d583732d2c3649dc89a0002d.zip
[bun dev] When `--disable-bun.js` flag is passed, don't send 500s for rendering the fallback
-rw-r--r--src/http.zig13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/http.zig b/src/http.zig
index 59920003c..6503d6b0e 100644
--- a/src/http.zig
+++ b/src/http.zig
@@ -84,6 +84,9 @@ pub const RequestContext = struct {
full_url: [:0]const u8 = "",
res_headers_count: usize = 0,
+ /// --disable-bun.js propagates here
+ pub var fallback_only = false;
+
pub fn getFullURL(this: *RequestContext) [:0]const u8 {
if (this.full_url.len == 0) {
if (this.bundler.options.origin.isAbsolute()) {
@@ -213,7 +216,13 @@ pub const RequestContext = struct {
};
defer this.done();
- try this.writeStatus(500);
+
+ if (RequestContext.fallback_only) {
+ try this.writeStatus(200);
+ } else {
+ try this.writeStatus(500);
+ }
+
const route_name = if (route_index > -1) this.matched_route.?.name else this.url.pathname;
if (comptime fmt.len > 0) Output.prettyErrorln(fmt, args);
Output.flush();
@@ -2390,6 +2399,7 @@ pub const Server = struct {
timer: std.time.Timer = undefined,
transform_options: Api.TransformOptions,
javascript_enabled: bool = false,
+ fallback_only: bool = false,
pub fn onTCPConnection(server: *Server, conn: tcp.Connection, comptime features: ConnectionFeatures) void {
conn.client.setNoDelay(true) catch {};
@@ -2973,6 +2983,7 @@ pub const Server = struct {
}
if (debug.fallback_only) {
+ RequestContext.fallback_only = true;
RequestContext.JavaScriptHandler.javascript_disabled = true;
}