refactor(proxy): 统一代理路径配置从 /ollama-proxy 到 /proxy
- 将 nginx 反向代理路径从 /ollama-proxy 修改为 /proxy - 更新 .env.development 和 .env.example 中的 VITE_OLLAMA_API_URL 配置 - 修改 src/config/setting.ts 中的默认代理路径配置 - 更新 vite.config.ts 中的代理配置路径映射 - 优化代码格式化和多行语句的换行处理 - 调整打包配置中的文件命名逻辑格式
This commit is contained in:
@@ -9,7 +9,7 @@ VITE_APP_NAME=后台管理(开发环境)
|
||||
VITE_AI_API_URL=/ai-proxy
|
||||
|
||||
# Ollama 原生接口(开发环境建议走同源反代,避免浏览器 CORS)
|
||||
VITE_OLLAMA_API_URL=/ollama-proxy
|
||||
VITE_OLLAMA_API_URL=/proxy
|
||||
|
||||
# 如果 AI 网关启用了鉴权(401 Not authenticated),填入你的 Key(仅供本机 dev server 使用)
|
||||
# 不要加 VITE_ 前缀,避免被打包进前端
|
||||
|
||||
@@ -12,7 +12,7 @@ VITE_FILE_SERVER=https://your-file-server.com
|
||||
VITE_AI_API_URL=https://ai-api.websoft.top/api/v1
|
||||
|
||||
# Ollama 原生接口(默认端口 11434)
|
||||
# - 开发环境推荐走同源反代:VITE_OLLAMA_API_URL=/ollama-proxy(配合 vite.config.ts)
|
||||
# - 开发环境推荐走同源反代:VITE_OLLAMA_API_URL=/proxy(配合 vite.config.ts)
|
||||
# - 生产环境不要直接用 http(会混合内容被拦截),建议 Nginx 反代成同源 https
|
||||
VITE_OLLAMA_API_URL=http://47.119.165.234:11434
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ VITE_AI_API_URL=/ai-proxy
|
||||
如果你要直接用原生 Ollama(`http://<host>:11434`),生产环境同样建议走同源反代(避免 CORS + https 混合内容):
|
||||
|
||||
```nginx
|
||||
location /ollama-proxy/ {
|
||||
location /proxy/ {
|
||||
proxy_pass http://47.119.165.234:11434/;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host 47.119.165.234;
|
||||
@@ -63,7 +63,7 @@ location /ollama-proxy/ {
|
||||
然后把 `VITE_OLLAMA_API_URL` 配置为:
|
||||
|
||||
```bash
|
||||
VITE_OLLAMA_API_URL=/ollama-proxy
|
||||
VITE_OLLAMA_API_URL=/proxy
|
||||
```
|
||||
|
||||
## 3) 关于 API Key
|
||||
|
||||
@@ -26,7 +26,7 @@ export const AI_API_URL =
|
||||
// Note: browsers cannot call http from an https site (mixed-content); prefer same-origin proxy.
|
||||
export const OLLAMA_API_URL =
|
||||
import.meta.env.VITE_OLLAMA_API_URL ||
|
||||
(import.meta.env.DEV ? '/ollama-proxy' : 'http://47.119.165.234:11434');
|
||||
(import.meta.env.DEV ? '/proxy' : 'http://47.119.165.234:11434');
|
||||
|
||||
/**
|
||||
* 以下配置一般不需要修改
|
||||
|
||||
@@ -70,7 +70,10 @@ export default defineConfig(({ command, mode }) => {
|
||||
// 代理配置
|
||||
proxy: {
|
||||
'/api': {
|
||||
target: env.VITE_API_URL || process.env.VITE_API_URL || 'https://server.websoft.top',
|
||||
target:
|
||||
env.VITE_API_URL ||
|
||||
process.env.VITE_API_URL ||
|
||||
'https://server.websoft.top',
|
||||
changeOrigin: true,
|
||||
secure: false,
|
||||
configure: (proxy, _options) => {
|
||||
@@ -78,12 +81,20 @@ export default defineConfig(({ command, mode }) => {
|
||||
console.log('proxy error', err);
|
||||
});
|
||||
proxy.on('proxyReq', (proxyReq, req, _res) => {
|
||||
console.log('Sending Request to the Target:', req.method, req.url);
|
||||
console.log(
|
||||
'Sending Request to the Target:',
|
||||
req.method,
|
||||
req.url
|
||||
);
|
||||
});
|
||||
proxy.on('proxyRes', (proxyRes, req, _res) => {
|
||||
console.log('Received Response from the Target:', proxyRes.statusCode, req.url);
|
||||
console.log(
|
||||
'Received Response from the Target:',
|
||||
proxyRes.statusCode,
|
||||
req.url
|
||||
);
|
||||
});
|
||||
},
|
||||
}
|
||||
},
|
||||
// OpenAI-compatible gateway reverse proxy (dev only).
|
||||
// Example:
|
||||
@@ -94,7 +105,10 @@ export default defineConfig(({ command, mode }) => {
|
||||
changeOrigin: true,
|
||||
secure: false,
|
||||
rewrite: (path) =>
|
||||
path.replace(/^\/ai-proxy/, env.AI_PROXY_REWRITE_PREFIX || '/api/v1'),
|
||||
path.replace(
|
||||
/^\/ai-proxy/,
|
||||
env.AI_PROXY_REWRITE_PREFIX || '/api/v1'
|
||||
),
|
||||
configure: (proxy) => {
|
||||
proxy.on('proxyReq', (proxyReq) => {
|
||||
// Inject auth for local dev to avoid putting API keys in the browser.
|
||||
@@ -110,17 +124,17 @@ export default defineConfig(({ command, mode }) => {
|
||||
}
|
||||
},
|
||||
// Ollama native API reverse proxy (dev only).
|
||||
// GET /ollama-proxy/api/tags -> http://47.119.165.234:11434/api/tags
|
||||
// POST /ollama-proxy/api/chat -> http://47.119.165.234:11434/api/chat
|
||||
'/ollama-proxy': {
|
||||
// GET /proxy/api/tags -> http://47.119.165.234:11434/api/tags
|
||||
// POST /proxy/api/chat -> http://47.119.165.234:11434/api/chat
|
||||
'/proxy': {
|
||||
target: 'http://47.119.165.234:11434',
|
||||
changeOrigin: true,
|
||||
secure: false,
|
||||
rewrite: (path) => path.replace(/^\/ollama-proxy/, '')
|
||||
rewrite: (path) => path.replace(/^\/proxy/, '')
|
||||
}
|
||||
},
|
||||
// 端口冲突时的处理
|
||||
strictPort: false, // 允许自动选择其他端口
|
||||
strictPort: false // 允许自动选择其他端口
|
||||
},
|
||||
// 预览服务器配置(用于生产构建预览)
|
||||
preview: {
|
||||
@@ -128,7 +142,7 @@ export default defineConfig(({ command, mode }) => {
|
||||
host: '0.0.0.0',
|
||||
open: true,
|
||||
cors: true,
|
||||
strictPort: false,
|
||||
strictPort: false
|
||||
},
|
||||
plugins: [
|
||||
vue({
|
||||
@@ -167,12 +181,13 @@ export default defineConfig(({ command, mode }) => {
|
||||
ext: '.br'
|
||||
}),
|
||||
// 打包分析
|
||||
isBuild && visualizer({
|
||||
filename: 'dist/stats.html',
|
||||
open: false,
|
||||
gzipSize: true,
|
||||
brotliSize: true
|
||||
})
|
||||
isBuild &&
|
||||
visualizer({
|
||||
filename: 'dist/stats.html',
|
||||
open: false,
|
||||
gzipSize: true,
|
||||
brotliSize: true
|
||||
})
|
||||
].filter(Boolean),
|
||||
css: {
|
||||
preprocessorOptions: {
|
||||
@@ -230,14 +245,19 @@ export default defineConfig(({ command, mode }) => {
|
||||
// 文件命名
|
||||
chunkFileNames: (chunkInfo) => {
|
||||
const facadeModuleId = chunkInfo.facadeModuleId
|
||||
? chunkInfo.facadeModuleId.split('/').pop().replace(/\.\w+$/, '')
|
||||
? chunkInfo.facadeModuleId
|
||||
.split('/')
|
||||
.pop()
|
||||
.replace(/\.\w+$/, '')
|
||||
: 'chunk';
|
||||
return `js/${facadeModuleId}-[hash].js`;
|
||||
},
|
||||
assetFileNames: (assetInfo) => {
|
||||
const info = assetInfo.name.split('.');
|
||||
const ext = info[info.length - 1];
|
||||
if (/\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/i.test(assetInfo.name)) {
|
||||
if (
|
||||
/\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/i.test(assetInfo.name)
|
||||
) {
|
||||
return `media/[name]-[hash].${ext}`;
|
||||
}
|
||||
if (/\.(png|jpe?g|gif|svg)(\?.*)?$/.test(assetInfo.name)) {
|
||||
|
||||
Reference in New Issue
Block a user