简体   繁体   English

socket.io on openshift with angular-fullstack

[英]socket.io on openshift with angular-fullstack

I generated a node.js app using Yeomans angular-fullstack generator. 我使用Yeomans angular-fullstack生成器生成了一个node.js应用程序。 Everything worked fine except the use of socket.io. 除了使用socket.io之外,一切正常。 After uploading my app to openshift using angular-fullstack:openshift, I got informed that I have to: 在使用angular-fullstack:openshift将我的应用程序上传到openshift之后,我得知我必须:

Openshift websockets use port 8000, you will need to update the client to connect to the correct port for sockets to work. Openshift websockets使用端口8000,您需要更新客户端以连接到正确的端口以使套接字工作。 in /client/app/components/socket/socket.service : var ioSocket = io.connect(' http://my-domain.rhcloud.com/:8000 ')" /client/app/components/socket/socket.service ioSocket = io.connect(' http://my-domain.rhcloud.com/:8000 ')“

I dont know where to do this. 我不知道该怎么做。 I am using socket.io version 1.0.6 which is shown inside package.json file. 我正在使用socket.io版本1.0.6,它显示在package.json文件中。

==> app-root/logs/nodejs.log <== /var/lib/openshift/xxx/app-root/runtime/repo/server/config/socketio.js:41 socket.address = socket.handshake.address.address + ':' + ^ TypeError: Cannot read property 'address' of null at Namespace. ==> app-root / logs / nodejs.log <== /var/lib/openshift/xxx/app-root/runtime/repo/server/config/socketio.js:41 socket.address = socket.handshake.address .address +':'+ ^ TypeError:无法在Namespace读取null的属性'address'。 (/var/lib/openshift/xxx/app-root/runtime/repo/server/config/socketio.js:41:46) at Namespace.EventEmitter.emit (events.js:95:17) at Namespace.emit (/var/lib/openshift/xxx/app-root/runtime/repo/node_modules/socket.io/lib/namespace.js:205:10) at /var/lib/openshift/xxx/app-root/runtime/repo/node_modules/socket.io/lib/namespace.js:172:14 at process._tickCallback (node.js:415:13) DEBUG: Program node server/app.js exited with code 8 DEBUG: Starting child process with 'node server/app.js' (/var/lib/openshift/xxx/app-root/runtime/repo/server/config/socketio.js:41:46)在Namespace.EventEmitter.emit(events.js:95:17)的Namespace.emit( /var/lib/openshift/xxx/app-root/runtime/repo/node_modules/socket.io/lib/namespace.js:205:10)at / var / lib / openshift / xxx / app-root / runtime / repo /node_modules/socket.io/lib/namespace.js:172:14 at process._tickCallback(node.js:415:13)DEBUG:程序节点服务器/ app.js退出,代码为8 DEBUG:使用'node'启动子进程服务器/ app.js'

By the way, the app, including socket.io, works fine on my local development machine! 顺便说一下,应用程序,包括socket.io,在我的本地开发机器上工作正常!

Thanks for any help! 谢谢你的帮助! Fall.Guy Fall.Guy

My working solution is now: 我的工作解决方案现在是:

I changed the creation of the openshift app to "not create a scalable app" (I disabled the -s switch in the yo angular-fullstack:openshift command) 我将openshift应用程序的创建更改为“不创建可伸缩的应用程序”(我在yo angular-fullstack:openshift命令中禁用了-s开关)

After that, I changed the connection of socket.io to: 之后,我将socket.io的连接更改为:

 var ioSocket = io('http://my-domain.rhcloud.com:8000', { // Send auth token on connection, you will need to DI the Auth service above // 'query': 'token=' + Auth.getToken() }); 

in the "/client/components/socket/socket.service.js" file. 在“/client/components/socket/socket.service.js”文件中。 Socket.io works now fine! Socket.io现在工作正常!

I'm not sure why openshift requires this, but you just need to modify your client code. 我不确定为什么openshift需要这个,但你只需要修改你的客户端代码。

In your client side code, you should have something like this: 在您的客户端代码中,您应该具有以下内容:

var socket = io();

You'll apparently need to update it to: 您显然需要将其更新为:

var socket = io('http://mywebsite.com:8000');

It's worth noting that there are plenty of other hosting providers (even free) which don't require you to jump through these hoops. 值得注意的是,还有很多其他托管服务提供商(甚至免费)不需要你跳过这些环节。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM