fix(Express.js) Express.js try to use function as hostname (#1914)

This commit is contained in:
Ciro Spaciari
2023-01-27 18:33:53 -03:00
committed by GitHub
parent 724f23c19f
commit c1d05cf623
2 changed files with 6 additions and 3 deletions

View File

@@ -448,6 +448,7 @@ pub const ServerConfig = struct {
args.base_url = URL.parse(args.base_uri);
}
} else {
const hostname: string =
if (has_hostname and std.mem.span(args.hostname).len > 0) std.mem.span(args.hostname) else "0.0.0.0";
const protocol: string = if (args.ssl_config != null) "https" else "http";
@@ -4370,6 +4371,7 @@ pub fn NewServer(comptime ssl_enabled_: bool, comptime debug_mode_: bool) type {
}
pub fn stopListening(this: *ThisServer, abrupt: bool) void {
httplog("stopListening", .{});
var listener = this.listener orelse return;
this.listener = null;
this.unref();
@@ -4434,6 +4436,7 @@ pub fn NewServer(comptime ssl_enabled_: bool, comptime debug_mode_: bool) type {
}
noinline fn onListenFailed(this: *ThisServer) void {
httplog("onListenFailed", .{});
this.unref();
var zig_str: ZigString = ZigString.init("");
@@ -4709,6 +4712,7 @@ pub fn NewServer(comptime ssl_enabled_: bool, comptime debug_mode_: bool) type {
}
pub fn listen(this: *ThisServer) void {
httplog("listen", .{});
if (ssl_enabled) {
BoringSSL.load();
const ssl_config = this.config.ssl_config orelse @panic("Assertion failure: ssl_config");

View File

@@ -43,13 +43,12 @@ export class Server extends EventEmitter {
const server = this;
if (typeof host === "function") {
onListen = host;
host = undefined;
}
if (typeof port === "function") {
onListen = port;
}
if (typeof port === "object") {
} else if (typeof port === "object") {
host = port?.host;
port = port?.port;
if (typeof port?.callback === "function") onListen = port?.callback;