From a0b4df745ed46071232a36fec679120ee9c67e21 Mon Sep 17 00:00:00 2001 From: GW_MC <72297530+GWMCwing@users.noreply.github.com> Date: Wed, 31 Dec 2025 18:03:54 +0800 Subject: [PATCH] fix upstream does not contain a target when init --- apps/api/src/services/nginx/info/upstream.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/apps/api/src/services/nginx/info/upstream.rs b/apps/api/src/services/nginx/info/upstream.rs index cd0f078..17dcdf2 100644 --- a/apps/api/src/services/nginx/info/upstream.rs +++ b/apps/api/src/services/nginx/info/upstream.rs @@ -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)) } }