Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ws://localhost:5678/socketcluster/ 不在以下合法域名列表中,请参考文档 #2

Closed
xiaoguozi opened this issue Nov 15, 2016 · 6 comments

Comments

@xiaoguozi
Copy link

xiaoguozi commented Nov 15, 2016

用remotedev启动后,小程序报ws://localhost:5678/socketcluster/ 不在以下合法域名列表中 这个怎么解决的

@charleyw
Copy link
Owner

因为微信小程序用websocket的话,需要在小程序后台配置一个合法的域名,而且不能有端口号。所以我在代码里面默认注掉了。

如果要用的话,要么开 无appid的,要嘛就得在本地配置一下
简单说一下(以mac机器为例,安全域名是websocket.example.com):

  1. /etc/hosts文件中添加一行:
sudo sh -c 'echo "127.0.0.1       websocket.example.com">> /etc/hosts'
  1. 启动remotedev的时候用80端口
sudo remotedev --hostname=localhost --port=80
  1. 连接的代码用新的地址
function configureStore() {
  return createStore(reducer, compose(devTools({
    hostname: 'websocket.example.com',
    port: 80,
    secure: false
  })));
}

我没有没有实测,不过思路大概是这样的。

@xiaoguozi
Copy link
Author

xiaoguozi commented Nov 16, 2016

@charleyw 试了一下没有无appid的,但是我这边提示
issue1

issue2

是版本不对么?

@charleyw
Copy link
Owner

我完了试一下,最近没弄,不知道微信是不是有更新

@BleemIs42
Copy link

@xiaoguozi 我也遇到这个问题

@lucienthink
Copy link

@charleyw 一样的问题,求解

@charleyw
Copy link
Owner

charleyw commented Mar 9, 2017

不好意思,好久没用了。这个问题的原因是因为微信的开发工具的运行环境里面不让使用 window 变量。而在那个 devtools的源码里面有一些地方使用了 window 变量,在执行过程中 window 是 undefined 所以会报错。

我把临时把源码改了,你更新一下代码应该就好了。

然后,微信开发工具提供了在开发环境不检查安全域名,所以,不需要使用我上面说的那么复杂的办法配置了。把开发环境不校验请求域名以及 TLS 版本选项勾上,就可以直接使用 localhost:5678访问了。

可以看一下 readme 我也更新了。

@charleyw charleyw closed this as completed Mar 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants