目录
1、单独配置文件 proxy.js
/**
* Created on 2023/1/16
* proxy 配置
*/
const httpsRE = /^https:\/\//;
/**
* Generate proxy
* @param list
*/
const createProxy = function(list = []) {
const ret = {};
for (const [prefix, target] of list) {
const isHttps = httpsRE.test(target);
ret[prefix] = {
target: target,
changeOrigin: true,
ws: true,
pathRewrite: {},
...(isHttps ? { secure: false } : {}),
};
}
return ret;
}
module.exports = {
createProxy
};
2、vue.config.js 中引用
// 配置代理
const {createProxy} = require('../build/proxy');
// url
const URL = 'https://********.com';
const PROXY = [
["/admin",URL],
["/product",URL],
["/brand",URL]
]
// 代理
proxyTable: createProxy(PROXY),