处理 build

pull/1/head
sin 2019-05-09 14:20:37 +08:00
parent b539420d6f
commit 9019717451
2 changed files with 49 additions and 25 deletions

View File

@ -1,9 +1,38 @@
// production 配置文件
module.exports = {
'/admin-api -> http://180.167.213.26:18083/': {
'/admin-api/': {
target: 'http://api.shop.iocoder.cn:18099/admin-api',
changeOrigin: true,
pathRewrite: {},
},
'/server/api -> https://preview.pro.ant.design/': {
'/product-api/': {
target: 'http://api.shop.iocoder.cn:18099/product-api',
changeOrigin: true,
pathRewrite: {},
},
'/order-api/': {
target: 'http://api.shop.iocoder.cn:18099/order-api',
changeOrigin: true,
pathRewrite: {},
},
'/promotion-api/': {
target: 'http://api.shop.iocoder.cn:18099/promotion-api',
changeOrigin: true,
pathRewrite: {},
},
'/pay-api/': {
target: 'http://api.shop.iocoder.cn:18099/pay-api',
changeOrigin: true,
pathRewrite: {},
},
'/user-api/': {
target: 'http://api.shop.iocoder.cn:18099/user-api',
changeOrigin: true,
pathRewrite: {},
},
'/server/api/': {
target: 'https://preview.pro.ant.design/',
changeOrigin: true,
pathRewrite: { '^/server': '' },
},

View File

@ -18,37 +18,32 @@ module.exports = function(config) {
console.info(chalkSuccess('build proxy.%s.config 配置!'), process.env.NODE_ENV);
const proxys = [];
if (!config) {
console.log(chalkError('proxy.%s.config 没有配置!'), process.env.NODE_ENV);
}
for (const key in config) {
let source;
let target;
if (/->/.test(key)) {
const keys = key.toString().split('->');
let source;
let target;
if (keys.length <= 1) {
// 没有 ->
source = key;
target = config.target;
} else {
source = keys[0].trim();
target = keys[1].trim();
}
if (typeof config !== 'object') {
console.log(
chalkError('%s: proxy.%s.config 初始化失败 config 类型为 object!'),
key,
process.env.NODE_ENV
);
break;
}
proxys.push(proxy(source, ObjectAssign({ target }, config[key])));
source = keys[0].trim();
target = keys[1].trim();
} else {
source = key;
target = config[key].target;
}
if (typeof config !== 'object') {
console.log(
chalkError('%s: proxy.%s.config 初始化失败 config 类型为 object!'),
key,
process.env.NODE_ENV
);
break;
}
proxys.push(proxy(source, ObjectAssign({ target }, config[key])));
}
return proxys;