this problem is the same as that mentioned in tutorial )
clone https://github.com/umijs/umi-.
its .webpackrc.js is as follows
export default {
"proxy": {
"/api": {
"target": "http://jsonplaceholder.typicode.com/",
"changeOrigin": true,
"pathRewrite": { "^/api" : "" }
}
},
}
http://jsonplaceholder.typico. is a test platform
/ user GET method can return some mock user
/ user POST body: {" id ": 22," name ":" test "}, it will return {" id ": 22," name ":" test "}
npm start is http://localhost:8000, according to the proxy, set in webpack. When we visit http://localhost:800/api/users
, webpack"s devServer will help us proxy to http://jsonplaceholder.typicode.com/users
after the above proxy is set:
GET
http://localhost:8000/api/users
is normal
POST
http://localhost:8000/api/users
with body data will be blocked by proxy server, as shown in indeed to request http://jsonplaceholder.typicode.com
,, but body will not be sent, but will be blocked . I added the "host" field to header according to the solution mentioned in issue above, but it didn"t work.
Please have a look at it, otherwise I can only set cross-domain settings on my own backend server, and then all url developed will have cross-domain settings.