Sails socket io 连接到与传入的 URL 不同的 URL [英] Sails socket io connecting to a different url than the one passed in

查看:14
本文介绍了Sails socket io 连接到与传入的 URL 不同的 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在生产中,当我尝试在 'https://something.com/api/中连接到我的套接字客户端时' 来自客户端 url 'https://something.com/' 我得到 404

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.

客户端主机

http://localhost:8080/

API 主机

http://localhost:1337/

HTML

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

JS

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

我的生产配置

客户端主机

https://something.com/ 

API 主机

https://something.com/api/

JS

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

我确保 autoConnect 被公然设置为 false,并且唯一的连接是通过 connect() 函数发生的.似乎无论我将什么字符串传递给 connect() 函数(仅在生产中),它都假定客户端 url (https://something.com/) 并从生产 url (https://something.com/api/).

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/).

推荐答案

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

文档可以在这里找到:http://sailsjs.com/documentation/reference/web-sockets/socket-client#?programmatic-configuration-using-iosails

这篇关于Sails socket io 连接到与传入的 URL 不同的 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆