我使用 Yeomans Angular-fullstack 生成器生成了一个 Node.js 应用程序。 除了使用 socket.io 之外,一切正常。使用 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. in
/client/app/components/socket/socket.service
: var ioSocket = io.connect('http://my-domain.rhcloud.com/:8000')"
我不知道在哪里执行此操作。我使用的是 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. (/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'
顺便说一句,该应用程序(包括 socket.io)在我的本地开发计算机上运行良好!
感谢您的帮助! 堕落者盖伊
最佳答案
我现在的工作解决方案是:
我将 openshift 应用程序的创建更改为“不创建可扩展应用程序”(我禁用了 yo angular-fullstack:openshift 命令中的 -s 开关)
之后,我将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() });
在“/client/components/socket/socket.service.js”文件中。 Socket.io 现在工作正常!
关于node.js - openshift 上的 socket.io 和 Angular-fullstack,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24845839/