diff options
author | 2022-03-20 04:38:04 -0700 | |
---|---|---|
committer | 2022-03-20 04:38:04 -0700 | |
commit | bc85dd2330763189e7f28941cc6e35903d6b49a9 (patch) | |
tree | f9ba5b865615c1f4a4032d28aea47e7b6fda4a7b /src/javascript/jsc/api/bun.zig | |
parent | a6b128590d104aa38a12ff20d820d02f0b6a8e6c (diff) | |
download | bun-bc85dd2330763189e7f28941cc6e35903d6b49a9.tar.gz bun-bc85dd2330763189e7f28941cc6e35903d6b49a9.tar.zst bun-bc85dd2330763189e7f28941cc6e35903d6b49a9.zip |
the events, they loop
Diffstat (limited to 'src/javascript/jsc/api/bun.zig')
-rw-r--r-- | src/javascript/jsc/api/bun.zig | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/javascript/jsc/api/bun.zig b/src/javascript/jsc/api/bun.zig index 64cc72ecc..d3b230243 100644 --- a/src/javascript/jsc/api/bun.zig +++ b/src/javascript/jsc/api/bun.zig @@ -954,6 +954,10 @@ pub const Class = NewClass( .rfn = Bun.readAllStdinSync, .ts = d.ts{}, }, + .startServer = .{ + .rfn = Bun.startServer, + .ts = d.ts{}, + }, }, .{ .main = .{ @@ -1001,6 +1005,28 @@ pub const Class = NewClass( }, ); +pub fn startServer( + _: void, + ctx: js.JSContextRef, + _: js.JSObjectRef, + _: js.JSObjectRef, + arguments: []const js.JSValueRef, + _: js.ExceptionRef, +) js.JSValueRef { + var vm = JSC.VirtualMachine.vm; + const handler = if (arguments.len > 0) JSC.JSValue.fromRef(arguments[0]) else JSC.JSValue.zero; + if (handler.isEmpty() or handler.isUndefinedOrNull() or !handler.isCell() or !handler.isCallable(ctx.ptr().vm())) { + Output.prettyWarnln("\"serverless\" export should be a function", .{}); + Output.flush(); + return JSC.JSValue.jsUndefined().asObjectRef(); + } + + JSC.C.JSValueProtect(ctx.ptr().ref(), handler.asObjectRef()); + var server = JSC.API.Server.init(vm.bundler.options.origin.getPortAuto(), handler, ctx.ptr()); + server.listen(); + return JSC.JSValue.jsUndefined().asObjectRef(); +} + pub fn allocUnsafe( _: void, ctx: js.JSContextRef, |