aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-10-06 00:01:02 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-10-06 00:01:02 -0700
commit3246efa5809c3bd031e1d08863e4b06beedd318e (patch)
tree721b8ce67f5099373365fca9845346e7b4ee152b /src
parent4060afb7c70dd3ba037bd23c813c22032e2dabe5 (diff)
downloadbun-3246efa5809c3bd031e1d08863e4b06beedd318e.tar.gz
bun-3246efa5809c3bd031e1d08863e4b06beedd318e.tar.zst
bun-3246efa5809c3bd031e1d08863e4b06beedd318e.zip
Implement Server.reload()
Diffstat (limited to 'src')
-rw-r--r--src/bun.js/api/server.zig48
1 files changed, 42 insertions, 6 deletions
diff --git a/src/bun.js/api/server.zig b/src/bun.js/api/server.zig
index 6a4261288..23c961480 100644
--- a/src/bun.js/api/server.zig
+++ b/src/bun.js/api/server.zig
@@ -2099,6 +2099,9 @@ pub fn NewServer(comptime ssl_enabled_: bool, comptime debug_mode_: bool) type {
.fetch = .{
.rfn = onFetch,
},
+ .reload = .{
+ .rfn = onReload,
+ },
},
.{
.port = .{
@@ -2116,6 +2119,37 @@ pub fn NewServer(comptime ssl_enabled_: bool, comptime debug_mode_: bool) type {
},
);
+ pub fn onReload(
+ this: *ThisServer,
+ ctx: js.JSContextRef,
+ _: js.JSObjectRef,
+ _: js.JSObjectRef,
+ arguments: []const js.JSValueRef,
+ exception: js.ExceptionRef,
+ ) js.JSObjectRef {
+ if (arguments.len < 1) {
+ JSC.throwInvalidArguments("Expected 1 argument, got 0", .{}, ctx, exception);
+ return js.JSValueMakeUndefined(ctx);
+ }
+
+ var args_slice = JSC.Node.ArgumentsSlice.from(ctx.bunVM(), arguments);
+ defer args_slice.deinit();
+ var new_config = ServerConfig.fromJS(ctx, &args_slice, exception);
+ if (exception.* != null) return js.JSValueMakeUndefined(ctx);
+
+ // only reload those two
+ if (new_config.onRequest != .zero) {
+ this.config.onRequest = new_config.onRequest;
+ this.config.onRequest.unprotect();
+ }
+ if (new_config.onError != .zero) {
+ this.config.onError = new_config.onError;
+ this.config.onError.unprotect();
+ }
+
+ return this.thisObject.asObjectRef();
+ }
+
pub fn onFetch(
this: *ThisServer,
ctx: js.JSContextRef,
@@ -2279,13 +2313,15 @@ pub fn NewServer(comptime ssl_enabled_: bool, comptime debug_mode_: bool) type {
}
}
- pub fn stop(this: *ThisServer) void {
- if (this.listener) |listener| {
- this.listener = null;
- this.unref();
- listener.close();
- }
+ pub fn stopListening(this: *ThisServer) void {
+ var listener = this.listener orelse return;
+ this.listener = null;
+ this.unref();
+ listener.close();
+ }
+ pub fn stop(this: *ThisServer) void {
+ this.stopListening();
this.deinitIfWeCan();
}