Skip to content

Commit

Permalink
Enable reusePort in Bun.serve() by default when using node:cluster (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarred-Sumner authored Aug 19, 2024
1 parent fa2e00f commit d55b5cc
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/bun.js/api/server.zig
Original file line number Diff line number Diff line change
Expand Up @@ -837,8 +837,8 @@ pub const ServerConfig = struct {
};

pub fn fromJS(global: *JSC.JSGlobalObject, arguments: *JSC.Node.ArgumentsSlice, exception: JSC.C.ExceptionRef) ServerConfig {
var env = arguments.vm.bundler.env;
const vm = JSC.VirtualMachine.get();
const vm = arguments.vm;
const env = vm.bundler.env;

var args = ServerConfig{
.address = .{
Expand All @@ -848,8 +848,13 @@ pub const ServerConfig = struct {
},
},
.development = true,

// If this is a node:cluster child, let's default to SO_REUSEPORT.
// That way you don't have to remember to set reusePort: true in Bun.serve() when using node:cluster.
.reuse_port = env.get("NODE_UNIQUE_ID") != null,
};
var has_hostname = false;

if (strings.eqlComptime(env.get("NODE_ENV") orelse "", "production")) {
args.development = false;
}
Expand Down

0 comments on commit d55b5cc

Please sign in to comment.