File tree Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -81,6 +81,55 @@ pnpm dev
81
81
VITE_MOONSHOT_KEY=你的_Moonshot_API_Key # 通常以 ` sk-` 开头,如 ` sk-xxxxxx`
82
82
` ` `
83
83
84
+
85
+ # # 🛠️ API 代理配置说明
86
+
87
+ 本项目采用纯前端架构,所有后端服务均由外部或本地其他服务提供。为解决开发环境中的跨域问题,项目使用了 ` Vite` 的代理功能 ` server.proxy` (详见[官方文档](https://vite.dev/config/server-options.html#server-proxy))
88
+
89
+ 以下是当前仓库的[代理配置](./vite.config.ts#L21)
90
+
91
+ ` ` ` ts
92
+ server: {
93
+ // ...
94
+ proxy: {
95
+ ' /spark' : {
96
+ target: ' https://spark-api-open.xf-yun.com' ,
97
+ changeOrigin: true,
98
+ ws: true,
99
+ rewrite: (path) => path.replace(/^\/ spark/, ' ' )
100
+ },
101
+ ' /siliconflow' : {
102
+ target: ' https://api.siliconflow.cn' ,
103
+ changeOrigin: true,
104
+ ws: true,
105
+ rewrite: (path) => path.replace(/^\/ siliconflow/, ' ' )
106
+ },
107
+ ' /moonshot' : {
108
+ target: ' https://api.moonshot.cn' ,
109
+ changeOrigin: true,
110
+ ws: true,
111
+ rewrite: (path) => path.replace(/^\/ moonshot/, ' ' )
112
+ }
113
+ }
114
+ },
115
+ // ...
116
+ ` ` `
117
+
118
+ # ## 注意事项
119
+
120
+ 1. ** 环境限制** : 该代理配置仅在开发环境(` development` )中生效。若生产环境部署时请根据实际情况调整服务器配置
121
+
122
+ 2. ** 路径匹配** : 请求路径需要与配置的代理路径前缀匹配,例如本地访问 ` /spark/v1/chat/completions` 会被直接代理到 ` https://spark-api-open.xf-yun.com/v1/chat/completions`
123
+
124
+ # ## 生产环境部署
125
+
126
+ 生产环境建议使用以下方案之一:
127
+
128
+ - 配置正确的 ` CORS` 响应头
129
+ - 使用 ` Nginx` 反向代理
130
+ - 统一域名和端口,避免跨域问题
131
+
132
+
84
133
# # 🌍 模拟/真实 API 模式切换
85
134
86
135
本项目提供了一个模拟开发模式,用于在本地开发环境或 Github 等部署环境中模拟调用大模型相关策略,无需调用真实 API 接口。该模式在 [src/config/env.ts](src/config/env.ts) 文件中定义,由以下代码控制:
You can’t perform that action at this time.
0 commit comments