OpenShift NodeJS部署:socket.io index.html端口分配等 [英] OpenShift NodeJS deployment : socket.io index.html port assignment, etc

查看:86
本文介绍了OpenShift NodeJS部署:socket.io index.html端口分配等的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在本地使用socket.io和express模块​​编写了一个nodeJS应用. 我想使用openshift进行托管. 因此,我将主.js更改为server.js,这似乎与openshift文件的索引等效,并将服务器端口设置更改为:

var server = require('http').createServer(app).listen(process.env.OPENSHIFT_NODEJS_PORT || 3000);

如某些帖子所述. 但是在git commit之后,我仍然得到:

远程:信息:socket.io已启动 远程:警告:引发错误:错误:收听EACCES 远程:调试:程序节点server.js退出,代码为0 偏僻的: 远程:调试:使用"node server.js"启动子进程

该网站无法正常工作.

由于该应用程序正在提供html文件,因此还有另外两个地方,其中提到的端口位于所提供的index.html中:

标题:

<script src='//localhost:3000/socket.io/socket.io.js'></script>

,并在javascript中找到html文件:

var socket = io.connect('//localhost:'+process.env.OPENSHIFT_NODEJS_PORT || 3000);

//服务器的初始变量和多列表 socket.on('clientConfig',onClientConfig);

似乎所有文件和模块都已上载,但EACCES错误仍然存​​在.

我觉得也许链接到localhost:3000的标题链接可能是跳过点,但是我不确定.任何人都有任何想法,这是什么问题? 另外,socket.io modules文件夹中没有:socket.io/socket.io.js文件,我感到困惑.

解决方案

我最近使用socket.io开发了一个聊天客户端应用程序,并且其中还包含了webrtc.通过对代码进行以下更改,我能够在openshift上部署该应用程序.

客户端

以类似的方式保持include脚本标签

<script src="/socket.io/socket.io.js"></script>

在声明io.connection时,请更改ip部分,以将应用程序以这种格式指向服务器.

var socket = io.connect('http://yourapp-domain.rhcloud.com:8000/', {'forceNew':true });

8000用于http,8443用于https

服务器端

io和服务器都应在同一端口上侦听,并且还应注意语句的运行顺序.

第1步:使用应用声明http服务器. (应用程序是从Express获得的)

var express = require('express');var app = express();) var server = require('http').Server(app);

第2步:

从socket.io声明io并将其与服务器对象组合. var io = require('socket.io').listen(server);

第3步:

现在,允许服务器监听openshift端口和ip.

server.listen(process.env.OPENSHIFT_NODEJS_PORT, process.env.OPENSHIFT_NODEJS_IP);

请特别注意所写语句的顺序,这是导致问题的顺序.

I locally wrote a nodeJS app using socket.io and express modules. I wanted to use openshift for hosting. So I changed the main .js to server.js which seems to be the index equivalent of the openshift file and changed the server port setting to:

var server = require('http').createServer(app).listen(process.env.OPENSHIFT_NODEJS_PORT || 3000);

as indicated in some posts. However after git commit, I am still getting:

remote: info: socket.io started remote: warn: error raised: Error: listen EACCES remote: DEBUG: Program node server.js exited with code 0 remote: remote: DEBUG: Starting child process with 'node server.js'

and the website doesn't work.

As the app is serving a html file, there are two more places, where the port is mentioned, which sit in the index.html that is served:

header:

<script src='//localhost:3000/socket.io/socket.io.js'></script>

and within javascript for the html file:

var socket = io.connect('//localhost:'+process.env.OPENSHIFT_NODEJS_PORT || 3000);

// intial vars and multi list from server socket.on('clientConfig', onClientConfig);

All files and modules are seemingly uploaded, but the EACCES error still prevails.

I get the feeling that maybe the header link to localhost:3000 might be the skipping point, but I am not sure. Anyone have any idea, what the problem is? Also, there is no : socket.io/socket.io.js file in the socket.io modules folder, which I find confusing.

解决方案

I had recently developed a chat client application using socket.io and also had webrtc in it. I was able to deploy the app on openshift by making the following changes into code.

Client Side

Keep the include script tag in a relative manner like so

<script src="/socket.io/socket.io.js"></script>

While declaring io.connection, change the ip part to point the application to server in this format.

var socket = io.connect('http://yourapp-domain.rhcloud.com:8000/', {'forceNew':true });

8000 is for http and 8443 is for https

Server Side

The io and the server should both be listening on the same port and the order in which the statements are run should also be given attention.

Step 1: Declare the http server using app. ( app is obtained from express)

var express = require('express');var app = express();) var server = require('http').Server(app);

Step 2:

Declare io from socket.io and combine it with the server object. var io = require('socket.io').listen(server);

Step 3:

Now, allow the server to listen to openshift port and ip.

server.listen(process.env.OPENSHIFT_NODEJS_PORT, process.env.OPENSHIFT_NODEJS_IP);

Please pay special attention to the order of the statements you write, it is the order which causes issues.

这篇关于OpenShift NodeJS部署:socket.io index.html端口分配等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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