feat: respect PORT env var

This commit is contained in:
Nurul Huda (Apon) 2026-06-21 02:06:25 +06:00
parent 95ddf411c6
commit 45d0691ccb
No known key found for this signature in database
GPG Key ID: 5D3F1DE2855A2F79
2 changed files with 8 additions and 1 deletions

View File

@ -10,7 +10,9 @@ pub const CacheConfig = struct {
};
pub const ServerConfig = struct {
/// Deprecated: This needs to be configured via `PORT` env variable or -Dport build arg. Will be removed in a future release.
port: ?u16 = null,
/// Deprecated: This needs to be configured via `ADDRESS` env variable or -Daddress build arg. Will be removed in a future release.
address: ?[]const u8 = null,
unix_path: ?[]const u8 = null,
workers: Worker = .{},

View File

@ -141,16 +141,21 @@ fn resolveOptions(alloc: std.mem.Allocator, inita: zx.Init, config: Config) !Con
const rootdir_env = envVar(alloc, inita, "ZIEX_ROOT_DIR");
const datadir_env = envVar(alloc, inita, "ZIEX_DATA_DIR");
const staticdir_env = envVar(alloc, inita, "ZIEX_STATIC_DIR");
const rootdir = rootdir_env orelse Constant.default_rootdir;
const port_env = envVar(alloc, inita, "PORT");
defer if (rootdir_env) |s| alloc.free(s);
defer if (datadir_env) |s| alloc.free(s);
defer if (staticdir_env) |s| alloc.free(s);
defer if (port_env) |s| alloc.free(s);
const rootdir = rootdir_env orelse Constant.default_rootdir;
const datadir = try std.fs.path.join(alloc, &.{ rootdir, datadir_env orelse Constant.default_datadir });
const staticdir = try std.fs.path.join(alloc, &.{ rootdir, staticdir_env orelse Constant.default_staticdir });
const port = if (port_env) |pe| std.fmt.parseInt(u16, pe, 10) catch return error.InvalidPort else cfg.server.port;
cfg.datadir = datadir;
cfg.staticdir = staticdir;
cfg.server.port = port;
switch (platform.os) {
.freestanding, .wasi => |os| {