1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
| /*
| * @Author : yuan
| * @Date : 2025-09-28 09:31:16
| * @LastEditors : yuan
| * @LastEditTime : 2025-09-28 09:40:50
| * @FilePath : \build\config\proxy.js
| * @Description :
| * Copyright 2025 OBKoro1, All Rights Reserved.
| * 2025-09-28 09:31:16
| */
| import configEnv from "../../src/config/env.js";
|
| export const createViteProxy = (env,envName = 'development') => {
| const { VITE_APP_PROXY, VITE_API_PREFIX,VITE_APP_ENV } = env
| // 不使用代理直接返回
| if (!JSON.parse(VITE_APP_PROXY)) return undefined
| const proxy = {
| [VITE_API_PREFIX]: {
| target: configEnv?.[envName || VITE_APP_ENV]?.VITE_API_BASE_URL,
| changeOrigin: true,
| rewrite: path => path.replace(new RegExp(`^${VITE_API_PREFIX}`), ''),
| },
| '/work-wx-static': {
| target: 'http://220.177.172.27:8100/', // 替换为实际地址
| changeOrigin: true,
| secure: false,
| // 如果需要查看代理日志,添加以下配置
| configure: (proxy, options) => {
| proxy.on('proxyReq', (proxyReq, req, res) => {
| console.log('代理请求:', req.method, req.url, '->', proxyReq.path);
| });
| }
| }
| }
| return proxy
| }
|
|