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:
2026-02-27 22:59:04 +08:00
parent b40326c3a9
commit b272ad09ce
5 changed files with 44 additions and 24 deletions

View File

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