简化了 vite 代理配置,
开发环境下后端使用自签名的 https 证书不报错, 忽视 Secure SameSite 等 cookie 相关安全检查;
This commit is contained in:
parent
7f4ccfd7fd
commit
e68652fe4c
|
|
@ -1,5 +1,8 @@
|
|||
# 本地环境
|
||||
ENV = development
|
||||
|
||||
# 本地环境接口地址
|
||||
VITE_API_URL = http://localhost:8888/
|
||||
# https 前面加斜杠,表示通过 vite 代理访问
|
||||
VITE_API_URL = '/https://api.example.com'
|
||||
|
||||
# 不加斜杠,表示直接访问,不使用代理
|
||||
# VITE_API_URL = 'https://api.example.com'
|
||||
|
|
|
|||
|
|
@ -28,11 +28,24 @@ const viteConfig = defineConfig((mode: ConfigEnv) => {
|
|||
open: JSON.parse(env.VITE_OPEN),
|
||||
hmr: true,
|
||||
proxy: {
|
||||
'/gitee': {
|
||||
target: 'https://gitee.com',
|
||||
[env.VITE_API_URL]: {
|
||||
target: env.VITE_API_URL.substring(1),
|
||||
ws: true,
|
||||
changeOrigin: true,
|
||||
rewrite: (path) => path.replace(/^\/gitee/, ''),
|
||||
rewrite: (path) => path.replace(env.VITE_API_URL, ''),
|
||||
configure(proxy, options){
|
||||
// https://github.com/http-party/node-http-proxy/tree/master
|
||||
options.secure = false; // https 允许自签名证书
|
||||
proxy.on('proxyRes', (proxyRes: any) => {
|
||||
let cookies = proxyRes.headers['set-cookie'];
|
||||
if(cookies) {
|
||||
for(let i in cookies){
|
||||
// 开发环境下忽视 cookie https/同源策略 相关安全检查
|
||||
cookies[i] = cookies[i].replace(/; *Secure|; *SameSite=\w+/ig, '');
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in New Issue