【问题标题】:Openshift Nodejs Socket.io issue, But 200 Ok responseOpenshift Nodejs Socket.io 问题,但 200 OK 响应
【发布时间】:2016-03-03 02:45:55
【问题描述】:

我已通过 Red-hat 在 OpenShift Cloud 平台中为 NodeJs 聊天应用程序部署了以下代码,我在控制台(F12)中没有收到任何错误,响应代码为 Ok 200..但应用程序无法正常工作

服务器(你可以在https://github.com/varund29/openshift/blob/master/index.js找到完整的源代码)

var express = require('express');
var app = express();
var server = require('http').createServer(app);
var io = require('socket.io').listen(server, { origins:'http://nodejs-atnodejs.rhcloud.com:8000' });
app.get('/', function (req, res) {
    res.sendfile('index.html');
});
io.on('connection', function (socket) {
    socket.on('chatmessage', function (msg) {
        console.log('index.js(socket.on)==' + msg);
        io.emit('chatmessage', msg);
    });
});

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

客户端(您可以在https://github.com/varund29/openshift/blob/master/index.html找到完整的源代码)

src="http://nodejs-atnodejs.rhcloud.com:8000/socket.io/socket.io.js  
src="http://code.jquery.com/jquery-1.11.1.js" 

     var socket = io.connect('http://nodejs-atnodejs.rhcloud.com:8000');
        $('button').click(function (e) {
            console.log('index.html($(button).click)=' + $('#m').val());
            socket.emit('chatmessage', $('#m').val());
            $('#m').val('');
            return false;
        });
        socket.on('chatmessage', function (msg) {
            console.log('index.html(socket.on)==' + msg);
            $('#messages').append($('<li>').text(msg));
        });

HTML 正文是

<ul id="messages"></ul>
    <form action="">
        <input id="m" autocomplete="off" />
        <button>Send</button>
    </form>

【问题讨论】:

标签: node.js socket.io openshift redhat


【解决方案1】:

当我运行您的代码时,我在 OpenShift Online 上的设备上的日志文件中收到以下错误:

Option log level is not valid. Please refer to the README.
Option polling duration is not valid. Please refer to the README.

所以我在您的index.js 文件中注释掉了以下几行:

io.set('log level', 1);                    // reduce logging
io.set('transports', ['xhr-polling']);
io.set("polling duration", 10);

而且它现在似乎工作正常。你可以在这里测试它:http://nodejs-cdaley.rhcloud.com/ 你可以在这里查看代码:https://github.com/developercorey/nodejs

【讨论】:

  • 请告诉我如何在 OpenShift 中找到日志文件。
  • 谢谢,现在可以正常工作了。我发现问题是如果 "dependencies": { "socket.io": "~9.6.0" } 它不起作用。使用“依赖项”工作正常:{“socket.io”:“1.2.0”} –
  • 您可以按照以下说明找到您的日志文件:developers.openshift.com/en/managing-log-files.html
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-04-23
  • 2020-02-09
  • 2011-01-14
  • 1970-01-01
  • 1970-01-01
  • 2013-03-08
  • 1970-01-01
相关资源
最近更新 更多