Sails socket io connecting to a different url than the one passed in

梦想与她 提交于 2019-12-02 08:03:38

问题


In production when I try to connect to my socket client in sails at 'https://something.com/api/' from the client url 'https://something.com/' I get a 404

https://something.com/socket.io/?__sails_io_sdk_version=0.13…owser&__sails_io_sdk_language=javascript&EIO=3&transport=polling&t=LFGJG5g 404 (Not Found)

When I establish a socket connection in sails on my local machine it works.

My Local Configuration.

CLIENT HOST

http://localhost:8080/

API HOST

http://localhost:1337/

HTML

<script src="sails.io.js" autoConnect="false"></script>

JS

connect() {
    this.socket = io.sails.connect('http://localhost:1337');// Works Fine
}

My Production Configuration

CLIENT HOST

https://something.com/ 

API HOST

https://something.com/api/

JS

connect() {
    this.socket = io.sails.connect('https://something.com/api/');// Does not work
}

I made sure that autoConnect was defiantly set to false and that the only connection was happening via the connect() function. It seems that no matter what string I pass into the connect() function ( only in production ), it assumes the client url (https://something.com/) and drops the suffix /api/ from the production url (https://something.com/api/).


回答1:


<script src="/js/dependencies/sails.io.js"></script>
<script type="text/javascript">
  io.sails.url = 'https://myapp.com'; // or where you want
</script>

The docs can be found here: http://sailsjs.com/documentation/reference/web-sockets/socket-client#?programmatic-configuration-using-iosails



来源:https://stackoverflow.com/questions/36348956/sails-socket-io-connecting-to-a-different-url-than-the-one-passed-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!