PORT environment variable to adjust port number

This commit is contained in:
Emil Lerch 2023-06-15 20:04:55 -07:00
parent f697e69d45
commit 46d73f3983
Signed by: lobo
GPG Key ID: A7B62D657EF764F8

View File

@ -362,7 +362,10 @@ pub fn main() !void {
var server = std.http.Server.init(allocator, .{ .reuse_address = true }); var server = std.http.Server.init(allocator, .{ .reuse_address = true });
defer server.deinit(); defer server.deinit();
const address = try std.net.Address.parseIp("0.0.0.0", PORT); const address = try std.net.Address.parseIp(
"0.0.0.0",
if (std.os.getenv("PORT")) |p| try std.fmt.parseInt(u16, p, 10) else PORT,
);
try server.listen(address); try server.listen(address);
const server_port = server.socket.listen_address.in.getPort(); const server_port = server.socket.listen_address.in.getPort();
log.info("listening on port: {d}", .{server_port}); log.info("listening on port: {d}", .{server_port});