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',