处理 build

This commit is contained in:
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 = { module.exports = {
'/admin-api -> http://180.167.213.26:18083/': { '/admin-api/': {
target: 'http://api.shop.iocoder.cn:18099/admin-api',
changeOrigin: true, changeOrigin: true,
pathRewrite: {}, 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, changeOrigin: true,
pathRewrite: { '^/server': '' }, pathRewrite: { '^/server': '' },
}, },

View File

@ -18,24 +18,20 @@ module.exports = function(config) {
console.info(chalkSuccess('build proxy.%s.config 配置!'), process.env.NODE_ENV); console.info(chalkSuccess('build proxy.%s.config 配置!'), process.env.NODE_ENV);
const proxys = []; const proxys = [];
if (!config) { if (!config) {
console.log(chalkError('proxy.%s.config 没有配置!'), process.env.NODE_ENV); console.log(chalkError('proxy.%s.config 没有配置!'), process.env.NODE_ENV);
} }
for (const key in config) { for (const key in config) {
if (/->/.test(key)) {
const keys = key.toString().split('->');
let source; let source;
let target; let target;
if (keys.length <= 1) { if (/->/.test(key)) {
// 没有 -> const keys = key.toString().split('->');
source = key;
target = config.target;
} else {
source = keys[0].trim(); source = keys[0].trim();
target = keys[1].trim(); target = keys[1].trim();
} else {
source = key;
target = config[key].target;
} }
if (typeof config !== 'object') { if (typeof config !== 'object') {
@ -49,7 +45,6 @@ module.exports = function(config) {
proxys.push(proxy(source, ObjectAssign({ target }, config[key]))); proxys.push(proxy(source, ObjectAssign({ target }, config[key])));
} }
}
return proxys; return proxys;
}; };