// 需要代理到的开发环境地址 const ProxyTargets = { 开发环境: 'https://webdev-webtest.jydev.jianyu360.com', 测试环境: 'https://jybx3-webtest.jydev.jianyu360.com' } const ProxyTarget = ProxyTargets['测试环境'] // 需要代理的请求前缀 const ProxyPrefixs = [ // 请求代理 'dataExport', 'course', 'jypay', 'subscribepay', 'front', 'entnicheNew', 'entbase', 'bigmember', 'userCenter', 'publicapply', 'jymessageCenter', 'jianyu-page', 'jyintegral', 'jydocs', 'jy-api', // 静态资源代理 'public-pc', 'pccss', 'js', 'css', 'antiRes', 'images/wx/', 'common-module', 'jyapi', 'jyMerge', 'commonFunctions', // 子应用资源代理,可实现正常访问对于环境的子应用,本地联调子应用时需移除 'page_big_pc', 'swordfish/page_big_pc', 'page_jy_pc', 'swordfish/page_web_pc', 'page_entpc', 'entpc', 'page_entbase_pc', 'orgpc', '/swordfish/integral', 'point' ] // 最终代理配置 const proxy = { '/api/jyapi/jybx': { target: ProxyTargets['开发环境'], changeOrigin: true, logLevel: 'debug', pathRewrite: { '^/api': '' } }, '/api': { target: ProxyTarget, changeOrigin: true, logLevel: 'debug', pathRewrite: { '^/api': '' } } } function getProxy (prefix) { return { value: { target: ProxyTarget, changeOrigin: true, logLevel: 'debug', pathRewrite: { ['^/' + prefix]: '/' + prefix } }, key: ['^/' + prefix] } } ProxyPrefixs.forEach(v => { const temp = getProxy(v) proxy[temp.key] = temp.value }) module.exports = proxy