When the proxy is configured, why still report the error of cross-domain request?

this is my own service run with nodejs. You can visit

.

clipboard.png
:

clipboard.png
:

clipboard.png
server.js

clipboard.png
still report the same error ("^") ("^")

Mar.01,2021

your access to port 8081 services on port 8080 must be cross-domain. If you need to set some protocol headers, you can access


header ('Access-Control-Allow-Origin: *'); / / allow all sources to access
header ('Access-Control-Allow-Methods: POST'); / / response type


how to write the url you requested. It looks like your url directly wrote port 8081, or the agent did not take effect


summarize how to solve this problem:
1. If the url of the request is misspelled, you should write axios.get ('/ getRecommend); instead of axios.get ('127.0.0.1 getRecommend); 8081 GetRecommend');
2. The server.js on the server needs to set the protocol header
/ / Cross-domain setting
app.all ('*', function (req, res, next) {
res.send ("recommended data");
res.header ("Access-Control-Allow-Credentials", true)
res.header ("Access-Control-Allow-Origin", "*")
res.header ("Access-Control-Allow-Headers", "X-Requested-With")
res.header ("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS")
res.header ("X-Powered-By", '3.2.1')
res.header ("Content-Type", "application/json;") Charset=utf-8 ")
next ()
})
3. Add a timestamp
axios.get ('/ getRencomment+time='+new Date (). GetTime ());

) to the url of the request
Menu