How to use nginx as a proxy to implement cross-domain requests?

A node service is set up locally, with the following code

let http = require("http")
let data = {
  name: "Andy",
  age: 27
}
http.createServer(function (request, response) {
  response.writeHead(200, {"Content-Type": "application/json;charset=utf-8"})
  response.end(JSON.stringify(data))
}).listen(8888)

console.log("")

nginx is configured as follows:

server {
  listen       80;
  server_name  localhost;
  location / {
      proxy_pass http://localhost:8888;
   }
}

I tried to use axios in my vue project to request data from the node service, but it was unsuccessful.

axios.get("localhost:8888").then(res => {

})

error message:

Failed to load localhost:8888: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.

I don"t quite understand when I write for the first time. Please tell me what"s wrong with it.

Jul.23,2021
The

prompt is obvious. Add the protocol http to the request

.
Menu