ホスティングサービス「dotcloud」でnodejsアプリをホストしようとしています。私のnodejsは、パッケージ「websocket」を使用して通信を処理します。すなわち。npm installwebsocket
私のアプリは、ラップトップのローカルホストで実行されているときにうまく機能します。しかし、アプリをdotcloudにデプロイすると、正しく機能しません。
何が起こっているかは次のとおりです。ブラウザでdotcloudのURLを指定します:pirate-captainlonate.dotcloud.com
次に、expressはexpress.get('/' .......){}を使用してGETリクエストを処理します。expressは、期待どおりに.htmlページをクライアントに提供します。次に、.htmlファイルはサーバーとのWebSocket接続を確立しようとします。繰り返しますが、これをローカルマシンで問題なく動作させることができます。ただし、接続は確立されていません。具体的には、dotcloudは間違いなく.htmlファイルを提供していますが、.htmlファイルはサーバーとのWebSocket接続を確立していません。しかし、connection.onerrorも呼び出されていません。それは奇妙だ。
これが私がしていることを理解するのに役立ついくつかのコードです:
クライアント側:
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.
サーバ側:
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
});
これは、それがどのように機能しているかを皆さんに示すのに十分なコードであるはずです。さて、あなたの一人はおそらく「>>dotcloudlogs」は何を示しているのかと尋ねるでしょう。
[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)
さて、私は本当にこれを機能させたいと思います。私はずっとこれにいます。私の質問に答えるのを手伝ってくれる必要があるものが他にあるかどうか教えてください。
ありがとう、
-ネイサン
補遺:これは、サーバーがhtmlファイルを送信する方法です。
xpress.get('/', function(req, res) {
res.sendfile(__dirname + '/public/game.html');
});