From 2d363b384ddb97278629cd5b314a2804be275645 Mon Sep 17 00:00:00 2001 From: qikongjian Date: Thu, 25 Sep 2025 19:51:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E6=94=B9=E6=88=90process.env?= =?UTF-8?q?.NEXT=5FPUBLIC=5FBASE=5FURL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/server-config.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/server-config.ts b/lib/server-config.ts index 01767ee..9463fb4 100644 --- a/lib/server-config.ts +++ b/lib/server-config.ts @@ -10,7 +10,14 @@ */ const localPost = async (url: string, data: any): Promise => { try { - const response = await fetch(url, { + // 使用环境变量中的 BASE_URL(生产要求使用 NEXT_PUBLIC_BASE_URL) + const baseUrl = process.env.NEXT_PUBLIC_BASE_URL || ''; + const isAbsolute = /^https?:\/\//i.test(url); + const normalizedBase = baseUrl.replace(/\/$/, ''); + const normalizedPath = url.startsWith('/') ? url : `/${url}`; + const fullUrl = isAbsolute ? url : `${normalizedBase}${normalizedPath}`; + + const response = await fetch(fullUrl, { method: 'POST', headers: { 'Content-Type': 'application/json',