it is not uncommon for local developers to request background interfaces, but local requests for background interfaces involve cross-domain problems.
webpack configuration proxy solves this problem very well.
however, there are several problems encountered in the process of using it. After looking through the documents and articles, what I said is not very popular. I have a few doubts. I"d like to ask you to explain
proxyTable: {
"/api": {
target: "https://cnodejs.org",
changeOrigin: true,
secure: false, //targetHTTPS, false
pathRewrite: {
"^/api": ""
}
}
}
see proxyTable, and tell me my questions and doubts:
first, the request method is axios, and the interface path is https://cnodejs.org/api/v1/topics
axios.get("/api/v1/topics")
.then((res)=> {console.log(res)})
.catch((err) => {console.log(err)})
doubt:
for the interface https://cnodejs.org/api/v1/topics
proxyTable the following configuration request Times 404
proxyTable: {
"/api": {
target: "https://cnodejs.org",
secure: false,
changeOrigin: true,
pathRewrite: {
"^/api": ""
}
}
}
proxyTable is configured as follows. Request is normal 200
proxyTable: {
"/api": {
target: "https://cnodejs.org",
secure: false,
}
}
question 1: about the first"/ api"
for example, there are interfaces
1, https://cnodejs.org/api/v1/topics
2, https://cnodejs/org/api/v2/topics
3, https://cnodejs/org/api/v2/topics
.
is the first "/ api"
the public part of the above interface / api
? All requests starting with / api are proxied through jsonplaceholder?
question 2: about pathRewrite
for example, there is an interface https://cnodejs.org/xxx/v1/topics
this interface does not have / api
part
pathRewrite: {
"^/api": "" //
}
what is the function of "^ / api":"
in the pathRewirte above, and what is the function of the symbol ^
?