P1.reactjs跨域解决

介绍

create-react-app + react-router 4.1 + fetch 2.0 + react 15.6

跨域

package.json里添加proxy

如下:

1
2
3
4
5
6
7
8
9
10
11
12
"proxy": {
"/target": {
"target": "http://rooturl"
},
"/api":{
"target": "http://192.168.90.85:3000", //后台地址
"changeOrigin": true,
"pathRewrite": {
"^/api" :""
}
}
}

引用: fecth(‘/target/somedirect’)
fetch(‘http://localhost/api/someAPI) //fetch自己本地