如何将包含NodeJs模块的Codeigniter应用程序部署到Bluemix?

我目前正在使用一些nodejs来处理一些实时特性的codeigniter应用程序,我使用socket.ioexpress来集成nodejs模块来开发一个实时聊天应用程序。 我试图将我的应用程序部署到我的codeigniter应用程序的PHP构buildbluemix,我创build了一个nodejs应用程序来托pipe我的nodejs服务器。 问题是我似乎无法连接到使用io.connect()的nodejs服务器套接字。 有没有办法做到这一点,而不必在代码中做一些重大的改变。 谢谢。

/*eslint-env node*/ //------------------------------------------------------------------------------ // node.js starter application for Bluemix //------------------------------------------------------------------------------ // This application uses express as its web server // for more info, see: http://expressjs.com var express = require('express'); //var socket = require('socket.io'); // cfenv provides access to your Cloud Foundry environment // for more info, see: https://www.npmjs.com/package/cfenv var cfenv = require('cfenv'); // create a new express server var app = express(); var http = require('http').Server(app); var io = require('socket.io').listen(http); // serve the files out of ./public as our main files app.use(express.static(__dirname + '/')); var people = []; var left = []; var connetcted = false; io.on('connection', function (client) { console.log("New client !"); console.log("socket.id", client.id); client.on('message', function (data) { console.log('Message received ' + data.name + ":" + data.message); //client.broadcast.emit( 'message', { name: data.name, message: data.message } ); io.emit('message', {name: data.name, message: data.message, to: data.to}); }); client.on('connected', function (data) { console.log('Message received ' + data); people[data.current] = data; connetcted = true; delete left[data.current]; //client.broadcast.emit( 'message', { name: data.name, message: data.message } ); io.emit('connected', {current: data.current, people: people}); client.on('disconnect', function () { connetcted = false; setTimeout(function () { if (connetcted === false) { left[data.current] = data; delete people[data.current]; io.emit('deconnexion', {current: data.current, left: left}); } }, 10000); }); }); client.on('notification_client', function (data) { console.log('Message received ' + data.name + ":" + data.id_client); //client.broadcast.emit( 'message', { name: data.name, message: data.message } ); io.emit('notification_client', {message: data.message, id_client: data.id_client}); }); client.on('notification', function (data) { console.log('notification received ' + data.event_id); //client.broadcast.emit( 'message', { name: data.name, message: data.message } ); io.emit('notification', {message: data.message, event_id: data.event_id, id_tenant: data.id_tenant}); //Pushbots.setMessage(data.message, 1); //Pushbots.customFields({"event_id": data.event_id}); //Pushbots.customNotificationTitle("CUSTOM TITLE"); //var token = "APA91bGaZBXL9yv-Gr__0TLju-eMP42oKNPJhTtPocf8ar3OLC736tvi26lcXATDnGw7Ode1B2ONcusTvAP7s2L_06jMo8PIQ1QgmRf9k_EBmn-BqWaZLSK026ZQLWUyoIjArgHF6ssP"; //Pushbots.pushOne(token, function (response) { // console.log(response); //}); }); }); // get the app environment from Cloud Foundry var appEnv = cfenv.getAppEnv(); // start server on the specified port and binding host app.listen(appEnv.port, '0.0.0.0', function() { // print a message when the server starts listening console.log("server starting on " + appEnv.url); }); 

       

网上收集的解决方案 "如何将包含NodeJs模块的Codeigniter应用程序部署到Bluemix?"

基于https://github.com/rauchg/chat-example我能够得到以下应用程序在Bluemix工作。 这似乎可能是调用http.listen()app.listen()

index.js

 var app = require('express')(); var http = require('http').Server(app); var io = require('socket.io')(http); app.get('/', function(req, res){ res.sendFile(__dirname + '/index.html'); }); io.on('connection', function(socket){ socket.on('chat message', function(msg){ io.emit('chat message', msg); }); }); http.listen(process.env.PORT, function(){ console.log('listening...'); }); 

的package.json

 { "name": "socket-chat-example", "version": "0.0.1", "description": "my first socket.io app", "dependencies": { "express": "4.10.2", "socket.io": "1.2.0" }, "scripts": { "start": "node index.js" } } 

的index.html

 <!doctype html> <html> <head> <title>Socket.IO chat</title> <style> * { margin: 0; padding: 0; box-sizing: border-box; } body { font: 13px Helvetica, Arial; } form { background: #000; padding: 3px; position: fixed; bottom: 0; width: 100%; } form input { border: 0; padding: 10px; width: 90%; margin-right: .5%; } form button { width: 9%; background: rgb(130, 224, 255); border: none; padding: 10px; } #messages { list-style-type: none; margin: 0; padding: 0; } #messages li { padding: 5px 10px; } #messages li:nth-child(odd) { background: #eee; } </style> </head> <body> <ul id="messages"></ul> <form action=""> <input id="m" autocomplete="off" /><button>Send</button> </form> <script src="https://cdn.socket.io/socket.io-1.2.0.js"></script> <script src="http://code.jquery.com/jquery-1.11.1.js"></script> <script> var socket = io(); $('form').submit(function(){ socket.emit('chat message', $('#m').val()); $('#m').val(''); return false; }); socket.on('chat message', function(msg){ $('#messages').append($('<li>').text(msg)); }); </script> </body> </html>