fix upstream does not contain a target when init

This commit is contained in:
GW_MC
2025-12-31 18:03:54 +08:00
parent 46801fba99
commit a0b4df745e

View File

@@ -54,13 +54,13 @@ impl NginxConfigProvider for UpstreamInfo {
.iter()
.map(|target| target.to_nginx_config(Some(indent.unwrap_or(0) + INDENT_SIZE)))
.collect();
format!(
"upstream {} {{\n{}\n}}",
self.name,
targets_config.join("\n".indent(indent.unwrap_or(0) + INDENT_SIZE).as_str())
)
.indent(indent.unwrap_or(0))
let targets_config_str = if targets_config.is_empty() {
"server 127.0.0.1:65535 down; # placeholder target".to_string()
} else {
targets_config.join("\n")
}
.indent(indent.unwrap_or(0) + INDENT_SIZE);
format!("upstream {} {{\n{}\n}}", self.name, targets_config_str).indent(indent.unwrap_or(0))
}
}