Created by: yuanalexwu
When we fetching data from another origin we should use proxy. Normally, we set proxy option as String in pakcage.json:
{
"proxy": "http://abc.com"
}
It works as expected.
But, if we have several apis that are cross origin.Then we should set proxy option as an Object:
{
"proxy": {
"/api/foo": {
"target": "http://abc.com"
},
"/api/bar": {
"target": "http://def.com"
},
}
}
It doesn't work because of the proxy request header's host
does not change the origin to the target
.So we still get cross origin error
We can fix it as below:
{
"proxy": {
"/api/foo": {
"target": "http://abc.com" ,
"changeOrigin": true
},
"/api/bar": {
"target": "http://def.com",
"changeOrigin": true
},
}
}
I think it should be a default behavior both in String and Object proxy option