vuejs / vue-cli

🛠️ webpack-based tooling for Vue.js Development
https://cli.vuejs.org/
MIT License
29.76k stars 6.33k forks source link

The url of `sockjs-node` is not same as the browser url (Domain) #3973

Open dy86 opened 5 years ago

dy86 commented 5 years ago

Version

3.7.0

Reproduction link

https://github.com/dy86/vue-cli-issue-demo.git

Environment info

System:
    OS: macOS 10.14.4
    CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
  Binaries:
    Node: 10.15.3 - /usr/local/bin/node
    Yarn: 1.15.2 - /usr/local/bin/yarn
    npm: 6.4.1 - /usr/local/bin/npm
  Browsers:
    Chrome: Not Found
    Firefox: Not Found
    Safari: 12.1
  npmGlobalPackages:
    @vue/cli: 3.5.5

Steps to reproduce

使用vue-create-app创建好的项目,直接支行npm run serve

我的电脑IP:10.0.1.10

当访问http://localhost:8080/时`sockjs-node`的url为:http://10.0.1.10:8080/sockjs-node/info?t=xxxxxx

当访问http://10.0.1.10:8080/时`sockjs-node`的url为:http://localhost:8080/sockjs-node/info?t=xxxxxx

总是相反的,这样就产生了CORS的错误信息:

Access to XMLHttpRequest at 'http://localhost:8080/sockjs-node/info?t=1557469168759' from origin 'http://10.0.1.10:8080' has been blocked by CORS policy: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.

What is expected?

`sockjs-node`的url与访问的url相对应,避免控制台出现CORS报错信息

What is actually happening?

我的电脑IP:10.0.1.10

当访问http://localhost:8080/时`sockjs-node`的url为:http://10.0.1.10:8080/sockjs-node/info?t=xxxxxx

当访问http://10.0.1.10:8080/时`sockjs-node`的url为:http://localhost:8080/sockjs-node/info?t=xxxxxx

总是相反的,这样就产生了CORS的错误信息:

Access to XMLHttpRequest at 'http://localhost:8080/sockjs-node/info?t=1557469168759' from origin 'http://10.0.1.10:8080' has been blocked by CORS policy: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.

我不确定这个是不是vue-cli的问题,是不是webpack-dev-server的bug呢?

zhaojh329 commented 5 years ago

我也遇到同样的问题。

dy86 commented 5 years ago

今天终于发现的问题的原因,我的chrome安装了一个cors的扩展,移除就不再报错了。

虽然不报错,不过localhost本机IP访问项目时,sockjs对应的正好是相反的,这个也应该是个bug吧?

比如我访问的是: http://localhost:8081/ sockjs的地址却是: ws://10.0.1.10:8081/sockjs-node/407/wexbc0pt/websocket

Ttou commented 4 years ago

这个问题和chrome无关,我用火狐也报错,cli 版本 4.4.6 和 4.5.0 都会出问题

Ttou commented 4 years ago

问题找到了,本地有软件开了全局代理,关掉就好了