problem description
use vue-cli to start the foreground port 8080 and the local eclipse to start the background port 8180, so you need to configure the proxy.
the proxy is configured according to CSDN"s tutorial, but the foreground browser reports an error
a href= "http://localhost" rel=" nofollow noreferrer "http://localhost:8080/api/springdemo/getUserByGet?userName=111 400 (Bad Request)
, and the backend cannot receive a message.
the environmental background of the problems and what methods you have tried
The agent should actually be successful, because browsers can receive the returned results by directly accessing the http://localhost:8080/api/springdemo/getUserByGet?userName=111
, but not through the this.$ajax.post ( http://localhost:8080/api/springdemo/getUserByGet?userName=111", {}) access.
related codes
in config/index.js, introduce the following configuration.
proxy: {
"/api": {
target: "http://localhost:8180", //
changeOrigin: true, //
pathRewrite: {
"^/api": "" // "/api" "/"
}
}
}
looked at the normal startup project and configured the agent to start the log:
[HPM] Proxy created: / apis-> https://apitest.miaomore.com
[HPM] Proxy rewrite rule created:" ^ / apis "~ >"
but I carefully follow the tutorial, but did not type these two lines of agent log, indicating that there is still something wrong with the configuration, please take a look at it for me.
-follow-up supplement-
found that it was not that the agent did not take effect, but the front-end request reported an error of 403, which caused me to think that the agent was out of order.
currently, only login (POST) cannot achieve proxy access, and other get request proxies are available. Please help me with the analysis.
this.$ajax.post("apis/login", {
domainAccount: this.loginForm.domainAccount,
password: this.loginForm.password
}).then((response) => {...}