エクスプレスルートまたはルーターページ内のすべてのsocket.io機能を維持することにより、エクスプレスノードアプリをクリーンアップしようとしています(ここで回答された質問に依存しています: Nodejs include socket.io in router page )。なんらかの理由で、ソケット接続が開かれません (「成功」がログに記録されません)。
//app.js
server = http.createServer(app).listen(3000);
app.get('/', function(req,res){
routes.index(req,res,app,server);
});
私の routes.index は次のようになります。
//routes.index
var socketio = require('socket.io');
exports.index = function(req,res,app,server){
var io = socketio.listen(server);
server.listen(3000);
console.log("routed correctly?"); //yes, it is routed correctly.
io.sockets.on('connection', function (socket) {
console.log("success");
});
res.render('index');
};
何か案は?とても有難い。