处理 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,37 +18,32 @@ 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) {
let source;
let target;
if (/->/.test(key)) { if (/->/.test(key)) {
const keys = key.toString().split('->'); const keys = key.toString().split('->');
source = keys[0].trim();
let source; target = keys[1].trim();
let target; } else {
if (keys.length <= 1) { source = key;
// 没有 -> target = config[key].target;
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])));
} }
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; return proxys;