Vite.config 配置Proxy服务器, 解决Rest API 访问SpringBoot接口时,跨域的Session一致性。
import { defineConfig, loadEnv } from 'vite'
export default defineConfig({
server: {
proxy: {
'/rest': {
target: loadEnv('', process.cwd()).VITE_API_URL,
changeOrigin: true
}
}
},
代理前
JSESSIONID=DA97DE3807A569A2F5524E8834434086; Path=/; HttpOnly
JSESSIONID=08433F457E2AA361D9E01391DEB56A3A; Path=/; HttpOnly
代理后
JSESSIONID=0DD0C41655082C91F91A3FCD2F8550AA
JSESSIONID=0DD0C41655082C91F91A3FCD2F8550AA