2025-10-21 16:50:33 +08:00
|
|
|
import { defineConfig } from 'vite'
|
|
|
|
|
import vue from '@vitejs/plugin-vue'
|
|
|
|
|
import { resolve } from 'path'
|
|
|
|
|
|
|
|
|
|
export default defineConfig({
|
|
|
|
|
plugins: [vue()],
|
|
|
|
|
resolve: {
|
|
|
|
|
alias: {
|
|
|
|
|
'@': resolve(__dirname, 'src')
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
server: {
|
2025-10-23 10:40:57 +08:00
|
|
|
port: 5173,
|
2025-10-23 17:50:12 +08:00
|
|
|
host: '0.0.0.0', // 允许外部访问
|
|
|
|
|
allowedHosts: true, // 允许所有主机访问
|
2025-10-21 16:50:33 +08:00
|
|
|
proxy: {
|
|
|
|
|
'/api': {
|
2025-10-23 17:50:12 +08:00
|
|
|
target: 'http://localhost:8080',
|
2025-10-21 16:50:33 +08:00
|
|
|
changeOrigin: true,
|
|
|
|
|
secure: false,
|
|
|
|
|
// 确保后端返回的 Set-Cookie 可被前端域接收与发送
|
2025-10-23 17:50:12 +08:00
|
|
|
cookieDomainRewrite: 'localhost',
|
2025-10-21 16:50:33 +08:00
|
|
|
cookiePathRewrite: '/',
|
|
|
|
|
configure: (proxy, _options) => {
|
|
|
|
|
proxy.on('error', (err, _req, _res) => {
|
|
|
|
|
console.log('proxy error', err);
|
|
|
|
|
});
|
|
|
|
|
proxy.on('proxyReq', (proxyReq, req, _res) => {
|
|
|
|
|
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);
|
|
|
|
|
const setCookie = proxyRes.headers['set-cookie'];
|
|
|
|
|
if (setCookie) {
|
|
|
|
|
console.log('Proxy Set-Cookie:', setCookie);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
build: {
|
|
|
|
|
outDir: 'dist',
|
|
|
|
|
assetsDir: 'assets'
|
|
|
|
|
}
|
|
|
|
|
})
|