aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js
diff options
context:
space:
mode:
authorGravatar MichaƂ Warda <michalwarda@users.noreply.github.com> 2023-02-13 12:08:11 +0100
committerGravatar GitHub <noreply@github.com> 2023-02-13 03:08:11 -0800
commitf310d7414b3a9863d99773317620e93c1e8b6693 (patch)
treeaa1f57ccbbe4a546329884da8ea3bc394fa92af4 /src/bun.js
parent739de2c9cd19736b6d088a9f127b52709e72909b (diff)
downloadbun-f310d7414b3a9863d99773317620e93c1e8b6693.tar.gz
bun-f310d7414b3a9863d99773317620e93c1e8b6693.tar.zst
bun-f310d7414b3a9863d99773317620e93c1e8b6693.zip
Add dynamic port assigning to Bun.serve (#2062)
Diffstat (limited to 'src/bun.js')
-rw-r--r--src/bun.js/api/server.zig7
1 files changed, 2 insertions, 5 deletions
diff --git a/src/bun.js/api/server.zig b/src/bun.js/api/server.zig
index 029ce6533..62d8f602a 100644
--- a/src/bun.js/api/server.zig
+++ b/src/bun.js/api/server.zig
@@ -408,10 +408,6 @@ pub const ServerConfig = struct {
}
}
- if (args.port == 0) {
- JSC.throwInvalidArguments("Invalid port: must be > 0", .{}, global, exception);
- }
-
if (args.base_uri.len > 0) {
args.base_url = URL.parse(args.base_uri);
if (args.base_url.hostname.len == 0) {
@@ -4308,7 +4304,8 @@ pub fn NewServer(comptime ssl_enabled_: bool, comptime debug_mode_: bool) type {
}
pub fn getPort(this: *ThisServer) JSC.JSValue {
- return JSC.JSValue.jsNumber(this.config.port);
+ var listener = this.listener orelse return JSC.JSValue.jsNumber(this.config.port);
+ return JSC.JSValue.jsNumber(listener.getLocalPort());
}
pub fn getPendingRequests(this: *ThisServer) JSC.JSValue {