2026-03-07 22:58:43 +08:00
|
|
|
|
import { defineConfig } from 'vite'
|
|
|
|
|
|
import react from '@vitejs/plugin-react'
|
|
|
|
|
|
import path from 'path'
|
|
|
|
|
|
import { fileURLToPath } from 'url'
|
|
|
|
|
|
|
|
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
|
|
|
|
|
|
|
|
|
|
export default defineConfig({
|
|
|
|
|
|
plugins: [react()],
|
|
|
|
|
|
resolve: {
|
|
|
|
|
|
alias: {
|
|
|
|
|
|
'@': path.resolve(__dirname, './src'),
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
server: {
|
|
|
|
|
|
port: 5174,
|
2026-03-22 08:34:28 +08:00
|
|
|
|
proxy: {
|
|
|
|
|
|
// 与 client 中「DEV 且未设 VITE_API_BASE_URL」配合:浏览器只访问 5174,由 Vite 转发到 Go
|
|
|
|
|
|
// 注意:前缀 `/api` 会匹配 `/api-docs`,必须把文档页排除,否则请求落到 Go 会 404
|
|
|
|
|
|
'/api': {
|
|
|
|
|
|
target: 'http://127.0.0.1:8080',
|
|
|
|
|
|
changeOrigin: true,
|
|
|
|
|
|
bypass(req) {
|
|
|
|
|
|
const u = req.url ?? ''
|
|
|
|
|
|
if (u === '/api-docs' || u.startsWith('/api-docs?') || u.startsWith('/api-docs/')) {
|
|
|
|
|
|
return false
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
'/uploads': { target: 'http://127.0.0.1:8080', changeOrigin: true },
|
|
|
|
|
|
},
|
2026-03-07 22:58:43 +08:00
|
|
|
|
},
|
|
|
|
|
|
})
|