使用动态API地址

This commit is contained in:
Kevin Wong
2026-01-14 17:49:23 +08:00
parent 9d4f8c7267
commit eb1ff2761d
2 changed files with 8 additions and 2 deletions

View File

@@ -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 {

View File

@@ -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;