diff --git a/flake.nix b/flake.nix index 976734e..7d585a8 100644 --- a/flake.nix +++ b/flake.nix @@ -122,7 +122,7 @@ config = cfg.config // { hmacKey = "@hmac@"; }; - server = cfg.server // { + server = lib.filterAttrs (_: v: v != null) cfg.server // { staticDir = "${cfg.package}/share/teapot/public"; }; } cfg.settings @@ -177,6 +177,11 @@ default = 8080; description = "The port to listen on."; }; + publicPort = lib.mkOption { + type = lib.types.nullOr lib.types.port; + default = null; + description = "Port used for generating public URLs. Defaults to the listen port."; + }; https = lib.mkOption { type = lib.types.bool; default = false; diff --git a/src/config.rs b/src/config.rs index 54be321..5dc9f55 100644 --- a/src/config.rs +++ b/src/config.rs @@ -33,6 +33,8 @@ pub struct ServerConfig { pub address: String, #[serde(default = "default_port")] pub port: u16, + #[serde(default, rename = "publicPort")] + pub public_port: Option, #[serde(default)] pub https: bool, #[serde( @@ -152,12 +154,13 @@ impl Config { } let scheme = if config.server.https { "https" } else { "http" }; let default_port = if config.server.https { 443 } else { 80 }; - if config.server.port == default_port || config.server.hostname.contains(':') { + let url_port = config.server.public_port.unwrap_or(config.server.port); + if url_port == default_port || config.server.hostname.contains(':') { config.url_prefix = format!("{scheme}://{}", config.server.hostname); } else { config.url_prefix = format!( "{scheme}://{}:{}", - config.server.hostname, config.server.port + config.server.hostname, url_port ); } Ok(config)