feat: 支持自定义API前缀配置

- 添加 VITE_API_BASE_PREFIX 环境变量支持
- 教程页面优先使用自定义前缀,未配置时使用浏览器访问地址
- 更新 .env.example 添加配置说明
This commit is contained in:
Zephyr
2025-09-01 22:13:08 +08:00
parent 19eaed2f32
commit 96cf49d3b7
2 changed files with 17 additions and 1 deletions

View File

@@ -23,6 +23,14 @@ VITE_APP_TITLE=Claude Relay Service - 管理后台
# 格式http://proxy-host:port # 格式http://proxy-host:port
#VITE_HTTP_PROXY=http://127.0.0.1:7890 #VITE_HTTP_PROXY=http://127.0.0.1:7890
# ========== 教程页面配置 ==========
# API 基础前缀(可选)
# 用于教程页面显示的自定义 API 前缀
# 如果不配置,则使用当前浏览器访问地址
# 示例https://api.example.com 或 https://relay.mysite.com
# VITE_API_BASE_PREFIX=https://api.example.com
# ========== 使用说明 ========== # ========== 使用说明 ==========
# 1. 复制此文件为 .env.local 进行本地配置 # 1. 复制此文件为 .env.local 进行本地配置
# 2. .env.local 文件不会被提交到版本控制 # 2. .env.local 文件不会被提交到版本控制

View File

@@ -1639,7 +1639,7 @@
</template> </template>
<script setup> <script setup>
import { ref, computed } from 'vue' import {computed, ref} from 'vue'
// 当前系统选择 // 当前系统选择
const activeTutorialSystem = ref('windows') const activeTutorialSystem = ref('windows')
@@ -1653,6 +1653,14 @@ const tutorialSystems = [
// 获取基础URL前缀 // 获取基础URL前缀
const getBaseUrlPrefix = () => { const getBaseUrlPrefix = () => {
// 优先使用环境变量配置的自定义前缀
const customPrefix = import.meta.env.VITE_API_BASE_PREFIX
if (customPrefix) {
// 去除末尾的斜杠
return customPrefix.replace(/\/$/, '')
}
// 否则使用当前浏览器访问地址
// 更健壮的获取 origin 的方法,兼容旧版浏览器和特殊环境 // 更健壮的获取 origin 的方法,兼容旧版浏览器和特殊环境
let origin = '' let origin = ''