From 17f4baa6da02958f03352e4529347271b196b307 Mon Sep 17 00:00:00 2001 From: Deloz Date: Sun, 9 Nov 2025 12:21:36 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=94=AF=E6=8C=81=20NOFX=5FBACKEND=5FPO?= =?UTF-8?q?RT=20=E7=8E=AF=E5=A2=83=E5=8F=98=E9=87=8F=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E7=AB=AF=E5=8F=A3=20(#764)=20-=20=E4=BC=98=E5=85=88=E7=BA=A7?= =?UTF-8?q?=EF=BC=9A=E7=8E=AF=E5=A2=83=E5=8F=98=E9=87=8F=20>=20=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=BA=93=E9=85=8D=E7=BD=AE=20>=20=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E5=80=BC=208080=20-=20=E4=BF=AE=E5=A4=8D=20.env=20=E4=B8=AD?= =?UTF-8?q?=E7=AB=AF=E5=8F=A3=E9=85=8D=E7=BD=AE=E4=B8=8D=E7=94=9F=E6=95=88?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=20-=20=E6=B7=BB=E5=8A=A0=E7=AB=AF?= =?UTF-8?q?=E5=8F=A3=E6=9D=A5=E6=BA=90=E6=97=A5=E5=BF=97=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 58bc3dd5..b8b1ed75 100644 --- a/main.go +++ b/main.go @@ -203,7 +203,6 @@ func main() { useDefaultCoins := useDefaultCoinsStr == "true" apiPortStr, _ := database.GetSystemConfig("api_server_port") - // 设置JWT密钥(优先使用环境变量) jwtSecret := strings.TrimSpace(os.Getenv("JWT_SECRET")) if jwtSecret == "" { @@ -317,12 +316,25 @@ func main() { fmt.Println(strings.Repeat("=", 60)) fmt.Println() - // 获取API服务器端口 + // 获取API服务器端口(优先级:环境变量 > 数据库配置 > 默认值) apiPort := 8080 // 默认端口 - if apiPortStr != "" { - if port, err := strconv.Atoi(apiPortStr); err == nil { + + // 1. 优先从环境变量 NOFX_BACKEND_PORT 读取 + if envPort := strings.TrimSpace(os.Getenv("NOFX_BACKEND_PORT")); envPort != "" { + if port, err := strconv.Atoi(envPort); err == nil && port > 0 { apiPort = port + log.Printf("🔌 使用环境变量端口: %d (NOFX_BACKEND_PORT)", apiPort) + } else { + log.Printf("⚠️ 环境变量 NOFX_BACKEND_PORT 无效: %s", envPort) } + } else if apiPortStr != "" { + // 2. 从数据库配置读取(config.json 同步过来的) + if port, err := strconv.Atoi(apiPortStr); err == nil && port > 0 { + apiPort = port + log.Printf("🔌 使用数据库配置端口: %d (api_server_port)", apiPort) + } + } else { + log.Printf("🔌 使用默认端口: %d", apiPort) } // 创建并启动API服务器