config: add publicPort option for URL generation

This commit is contained in:
4cuck committed 2026-03-11 04:23:02 -04:00
1 parent 54e3c0c1d2
commit a16fa4cb15
2 files changed
+11 -3

No files matched your search

+6 -1
View File
@@ -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;
+5 -2
View File
@@ -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<u16>,
#[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)