How many questions about webpack configuring proxyTable?

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 ^ ?

W
Mar.07,2021

the first question belongs to the request at the beginning of this field.
the second zone problem '^ / api':' is to change its path, to / api. As for the preceding ^ symbol, it belongs to the regular judgment
document as follows:
http-proxy-middleware options
option.pathRewrite: object/function, rewrite target's url path. Object-keys will be used as RegExp to match paths.

// rewrite path
pathRewrite: {'^/old/api' : '/new/api'}

// remove path
pathRewrite: {'^/remove/api' : ''}

// add base path
pathRewrite: {'^/' : '/basepath/'}

// custom rewriting
pathRewrite: function (path, req) { return path.replace('/api', '/base/api') }

Link description

Menu