I am trying to host a nodejs app on the hosting service "dotcloud". My nodejs uses the package "websocket" to handle communications. ie. npm install websocket
My app works great when it's running on localhost on my laptop. But when I deploy the app on dotcloud it does not work correctly.
Here is what is going on: You point your browser to the url on dotcloud: pirate-captainlonate.dotcloud.com
Then, express handles the GET request with express.get('/'.......){} express serves the .html page to the client as you would expect. The .html file in turn tries to establish the websocket connection with the server. Again I can get this to work just fine on my local machine. However, no connection is being established. Specifically, the dotcloud is definitely serving me the .html file, but the .html file is not establishing the websocket connection with the server. But connection.onerror isn't being called either. It's weird.
Here is some code to help you understand what I'm doing:
Client Side:
this.connection = new WebSocket('ws://pirate-captainlonate.dotcloud.com:1337');
this.connection.onerror = function (error) {
console.log("ERROR with the connection *sadface*");
};
**** Note that I note the onerror function here to show that I do indeed have it set up, but it's not being called. It would seem that no error is being thrown.
Server Side:
var webSocketServer = require('websocket').server; // websocket
var server = require('http').createServer();
var expr = require("express"); // load the express module
var xpress = expr(); // xpress now holds the server object
// Helps Node serve the game.html page upon a get request
xpress.configure(function() {
xpress.use(expr.static(__dirname + "/public"));
xpress.set("view options", {layout: false});
});
// All requests to root serve the game.html page
xpress.get('/', function(req, res) {
res.sendfile(__dirname + '/public/game.html');
});
// What ports to listen on
var webSocketsServerPort = 1337;
xpress.listen(8080);
server.listen(webSocketsServerPort, function() {
console.log((new Date()) + " Server is listening on port " + webSocketsServerPort);
});
// WebSocket Server
var wsServer = new webSocketServer({
httpServer: server
});
That should be enough code to show you guys how it's working. Now one of you will probably ask, what is ">> dotcloud logs" showing?
[www.0] ==> /var/log/supervisor/app.log <==
[www.0] Sat Feb 16 2013 02:57:59 GMT+0000 (UTC) Server is listening on port 1337
[www.0] ==> /var/log/supervisor/supervisord.log <==
[www.0] 2013-02-16 02:57:57,946 WARN Included extra file "/home/dotcloud/current/supervisord.conf" during parsing
[www.0] 2013-02-16 02:57:58,033 INFO RPC interface 'supervisor' initialized
[www.0] 2013-02-16 02:57:58,033 WARN cElementTree not installed, using slower XML parser for XML-RPC
[www.0] 2013-02-16 02:57:58,033 CRIT Server 'unix_http_server' running without any HTTP authentication checking
[www.0] 2013-02-16 02:57:58,038 INFO daemonizing the supervisord process
[www.0] 2013-02-16 02:57:58,039 INFO supervisord started with pid 140
[www.0] 2013-02-16 02:57:59,048 INFO spawned: 'app' with pid 154
[www.0] 2013-02-16 02:58:00,290 INFO success: app entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
[db.0] ==> /var/log/mongodb/mongodb.log <==
[db.0] Sat Feb 16 01:45:02 [conn4] end connection 127.0.0.1:51326 (0 connections now open)
Alright, well I'd really like to get this working. I've been at this forever. Let me know if there is anything else you guys need to help me answer my question.
Thanks,
--Nathan
Addendum: This is how server is sending the html file.
xpress.get('/', function(req, res) {
res.sendfile(__dirname + '/public/game.html');
});