本地起了个node服务,代码如下
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配置如下:
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://localhost:8888;
}
}
我尝试在vue项目中使用axios请求node服务中的数据,但是不成功。
axios.get('localhost:8888').then(res => {
})
报错信息:
Failed to load localhost:8888: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.
第一次写不太懂,请各位大佬指点一下哪里有错?
提示很明显,请求的时候加上协议http