From eb1ff2761d68d34942b69593382f3ed50fcbead0 Mon Sep 17 00:00:00 2001 From: Kevin Wong Date: Wed, 14 Jan 2026 17:49:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E5=8A=A8=E6=80=81API?= =?UTF-8?q?=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/app/page.tsx | 5 ++++- frontend/src/app/publish/page.tsx | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/frontend/src/app/page.tsx b/frontend/src/app/page.tsx index 134c747..f935dd2 100644 --- a/frontend/src/app/page.tsx +++ b/frontend/src/app/page.tsx @@ -3,7 +3,10 @@ import { useState, useEffect } from "react"; -const API_BASE = ""; // 使用相对路径,由 Next.js rewrite 代理到后端 +// 动态获取 API 地址:服务端使用 localhost,客户端使用当前域名 +const API_BASE = typeof window !== 'undefined' + ? `http://${window.location.hostname}:8006` + : 'http://localhost:8006'; // 类型定义 interface Material { diff --git a/frontend/src/app/publish/page.tsx b/frontend/src/app/publish/page.tsx index 62b2a51..b72eb7b 100644 --- a/frontend/src/app/publish/page.tsx +++ b/frontend/src/app/publish/page.tsx @@ -3,7 +3,10 @@ import { useState, useEffect } from "react"; import Link from "next/link"; -const API_BASE = ""; // 使用相对路径,由 Next.js rewrite 代理到后端 +// 动态获取 API 地址:服务端使用 localhost,客户端使用当前域名 +const API_BASE = typeof window !== 'undefined' + ? `http://${window.location.hostname}:8006` + : 'http://localhost:8006'; interface Account { platform: string;