mirror of
https://github.com/ziex-dev/ziex.git
synced 2026-07-20 02:29:36 -06:00
feat: respect PORT env var
This commit is contained in:
parent
95ddf411c6
commit
45d0691ccb
@ -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 = .{},
|
||||
|
||||
@ -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| {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user