nginx 反代模式下前端 API 调用走相对路径,VITE_API_BASE_URL 应为空字符串。用 || 会把空字符串当 falsy 导致 fallback 到 localhost:8010。改用 ?? 只在 undefined 时 fallback。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@@ -18,7 +18,7 @@ import { Loader2 } from './icons/commonIcons';
import { NotificationProvider } from './contexts/NotificationContext';
import './styles/markdown.css';
-const API_BASE = import.meta.env.VITE_API_BASE_URL || 'http://localhost:8010';
+const API_BASE = import.meta.env.VITE_API_BASE_URL ?? 'http://localhost:8010';
// 品牌配置 Context
export interface BrandingConfig { system_name: string; system_logo: string; icp_number: string }
@@ -7,7 +7,7 @@ import { Mail, Lock, GraduationCap, AlertCircle, CheckCircle2, Phone } from 'luc
import { User, Loader2 } from '../icons/commonIcons';
import { BrandingContext } from '../App';
// ==================== 忘记密码弹窗 ====================
@@ -4,7 +4,7 @@ import { useNavigate, useSearchParams } from 'react-router-dom';
import { authService } from '../services/authService';
import { Loader2, CheckCircle2, AlertCircle } from 'lucide-react';
/**
* SSO 回调页面
@@ -69,7 +69,7 @@ function convertUserToUserInfo(user: User): UserInfo {
const TOKEN_KEY = 'aigc_space_token';
const REFRESH_TOKEN_KEY = 'aigc_space_refresh_token';
const USER_INFO_KEY = 'aigc_space_user_info';
-const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || 'http://localhost:8010';
+const API_BASE_URL = import.meta.env.VITE_API_BASE_URL ?? 'http://localhost:8010';
// 认证状态变化事件名
const AUTH_CHANGE_EVENT = 'auth_state_change';
@@ -1,4 +1,4 @@
-const BASE_URL = import.meta.env.VITE_API_BASE_URL || 'http://127.0.0.1:8010';
+const BASE_URL = import.meta.env.VITE_API_BASE_URL ?? 'http://127.0.0.1:8010';
export interface FeatureFlags {
enable_openclaw: boolean;
@@ -1,13 +1,8 @@
import { Model } from '../types/models';
import { authService } from './authService';
-// API Base URL - 从环境变量获取,必须配置
-const API_BASE_URL = import.meta.env.VITE_API_BASE_URL;
-
-if (!API_BASE_URL) {
- console.error('VITE_API_BASE_URL 环境变量未配置,请在 .env 文件中设置 VITE_API_BASE_URL');
- throw new Error('VITE_API_BASE_URL 环境变量未配置');
-}
+// API Base URL - nginx 反代模式下为空字符串(走相对路径 /api/)
+const API_BASE_URL = import.meta.env.VITE_API_BASE_URL ?? '';
// API 响应类型定义
export interface ApiResponse<T> {
@@ -1,7 +1,7 @@
// API Base URL
// 密码强度等级
export type PasswordStrengthLevel = 'weak' | 'medium' | 'strong';
@@ -2,7 +2,7 @@ import { authService } from './authService';
// API Base URL - 从环境变量获取
// 默认改为 8010,与当前后端一致。若有自定义域名/端口,请在 .env.local 配置 VITE_API_BASE_URL
// 用户信息接口(与后端API对应)
export interface User {