diff options
author | 2023-06-05 04:31:13 -0700 | |
---|---|---|
committer | 2023-06-05 04:31:13 -0700 | |
commit | c87d65856c06a03a2470fdc1bd48bc4042dadaec (patch) | |
tree | d85b47e7d4df571f56adffeab6b7075b60d4bccb /src/bun.js/api | |
parent | 9b996e702ef32d03b01b745642292e7a747485fa (diff) | |
download | bun-c87d65856c06a03a2470fdc1bd48bc4042dadaec.tar.gz bun-c87d65856c06a03a2470fdc1bd48bc4042dadaec.tar.zst bun-c87d65856c06a03a2470fdc1bd48bc4042dadaec.zip |
[Inspector] Introduce `inspector: true` in Bun.serve()
This exposes the WebKit inspector debugger protocol over WebSockets at the endpoint `/bun:inspect` when `Bun.serve()`.
To enable, pass:
```js
Bun.serve({inspector: true, development: true, fetch(req){ /* rest of params *... });
```
Both `development` and `inspector` must be true, as this is very security sensitive to expose publicly.
Diffstat (limited to 'src/bun.js/api')
-rw-r--r-- | src/bun.js/api/server.zig | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/bun.js/api/server.zig b/src/bun.js/api/server.zig index 094f5e385..30889964d 100644 --- a/src/bun.js/api/server.zig +++ b/src/bun.js/api/server.zig @@ -136,6 +136,8 @@ pub const ServerConfig = struct { websocket: ?WebSocketServer = null, + inspector: bool = false, + pub const SSLConfig = struct { server_name: [*c]const u8 = null, @@ -741,7 +743,19 @@ pub const ServerConfig = struct { } if (arg.get(global, "development")) |dev| { - args.development = dev.toBoolean(); + args.development = dev.coerce(bool, global); + } + + if (arg.get(global, "inspector")) |inspector| { + args.inspector = inspector.coerce(bool, global); + + if (args.inspector and !args.development) { + JSC.throwInvalidArguments("Cannot enable inspector in production. Please set development: true in Bun.serve()", .{}, global, exception); + if (args.ssl_config) |*conf| { + conf.deinit(); + } + return args; + } } if (arg.getTruthy(global, "tls")) |tls| { @@ -5239,6 +5253,10 @@ pub fn NewServer(comptime ssl_enabled_: bool, comptime debug_mode_: bool) type { if (comptime debug_mode) { this.app.get("/bun:info", *ThisServer, this, onBunInfoRequest); + if (this.config.inspector) { + Bun__addInspector(ssl_enabled, this.app, this.globalThis); + } + this.app.get("/src:/*", *ThisServer, this, onSrcRequest); } @@ -5290,3 +5308,5 @@ pub const AnyServer = union(enum) { }; const welcome_page_html_gz = @embedFile("welcome-page.html.gz"); + +extern fn Bun__addInspector(bool, *anyopaque, *JSC.JSGlobalObject) void; |