接口改成process.env.NEXT_PUBLIC_BASE_URL

This commit is contained in:
qikongjian 2025-09-25 19:51:25 +08:00
parent 6427d074b2
commit 2d363b384d

View File

@ -10,7 +10,14 @@
*/
const localPost = async <T>(url: string, data: any): Promise<T> => {
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',