0%

Vite开启proxy代理日志

Vite 的 Proxy 主要是为了解决跨域问题,为了保证转发规则是否正确, 本文将介绍两种方法:

方法一:

1
pnpm dev --debug

方法二:

vim vite.config.js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// vite 相关配置
server: {
port: 80,
host: true,
open: true,
proxy: {
// https://cn.vitejs.dev/config/#server-proxy
'/dev-api': {
target: 'http://localhost:8080',
changeOrigin: true,
rewrite: (p) => {
console.log("[PROXY] " + p);
return p.replace(/^\/dev-api/, '');
}
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
➜  ruoyi-ui git:(codezm) ✗ pnpm run dev

> ruoyi@3.8.3 dev /Volumes/work/web/test
> vite

15:37:44
vite v2.9.14 dev server running at:

> Local: http://localhost:80/ 15:37:44
> Network: http://192.168.36.47:80/ 15:37:44
15:37:44
ready in 3368ms.

[PROXY]/dev-api/getInfo 15:37:50
[PROXY]/dev-api/getRouters 15:37:51
[PROXY]/dev-api/captchaImage 15:37:51
[PROXY]/dev-api/getInfo 15:37:52
[PROXY]/dev-api/getRouters 15:37:52
[PROXY]/dev-api/getInfo 15:37:53
[PROXY]/dev-api/getRouters 15:37:53
[PROXY]/dev-api/getInfo 15:37:53
[PROXY]/dev-api/system/dict/data/type/sys_normal_disable 15:37:53
[PROXY]/dev-api/system/post/list?pageNum=1&pageSize=10

参考