proxy: [
{
context: ['/user', '/rights', '/resource/getAdNotice'],
target: 'https://plus.m.jd.com',
secure: false,
changeOrigin: true,
headers: {
cookie: domCookies
}
},
{
context: ['/apis'],
target: 'https://rsp.jd.com/',
secure: false,
changeOrigin: true,
pathRewrite: {'^/apis': ''},
headers: {
cookie: domCookies,
referer: 'https://plus.m.jd.com'
}
}
]
post请求:
proxy:{
'/user':{
target: 'https://plus.m.jd.com',
secure: false,
changeOrigin: true,
headers: {
cookie: domCookies
}
},
'/rights':{
target: 'https://plus.m.jd.com',
secure: false,
changeOrigin: true,
},
'/resource/getAdNotice':{
target: 'https://plus.m.jd.com',
secure: false,
changeOrigin: true,
},
'/apis':{
target: 'https://rsp.jd.com/',
secure: false,
ws: true,
changeOrigin: true,
pathRewrite: {'^/apis': ''},
headers: {
referer: 'https://plus.m.jd.com'
}
},
'/apipost': {
target: 'https://rsp.jd.com/',
secure: false,
changeOrigin: true,
ws: true,
pathRewrite: {'^/apipost': ''},
headers: {
origin: 'https://plus.m.jd.com',
host: 'rsp.jd.com',
referer: 'https://plus.m.jd.com/index'
}
}
}
化简为:
proxy: [
{
context: ['/user', '/rights', '/resource/getAdNotice'],
target: 'https://plus.m.jd.com',
secure: false,
changeOrigin: true,
},
{
context: ['/apis'],
target: 'https://rsp.jd.com/',
secure: false,
ws: true,
changeOrigin: true,
pathRewrite: {'^/apis': ''},
headers: {
origin: 'https://plus.m.jd.com',
host: 'rsp.jd.com',
referer: 'https://plus.m.jd.com/index'
}
}
]
核心思想,正式中的header中有啥,代理中写上啥。
设置环境变量
new webpack.DefinePlugin({‘process.env.NODE_ENV’: JSON.stringify(‘care’)}),