nodejs对象#<server>没有方法&#39; configure&#39; </server>

时间:2015-01-13 08:06:38

标签: node.js redis socket.io

我有一个节点服务器:

var http = require('http');
var server = http.createServer().listen(4000);
var io = require('socket.io').listen(server);
var cookie_reader = require('cookie');
var querystring = require('querystring');

var redis = require('redis');
var sub = redis.createClient();

//Subscribe to the Redis chat channel
sub.subscribe('chat');

//Configure socket.io to store cookie set by Django
io.configure(function(){
    io.set('authorization', function(data, accept){
        if(data.headers.cookie){
            data.cookie = cookie_reader.parse(data.headers.cookie);
            return accept(null, true);
        }
        return accept('error', false);
    });
    io.set('log level', 1);
});

当我运行它时会出现错误Object #<Server> has no method 'configure' 我搜索了它,但没有找到任何特定的解决方案。

这里有什么不对吗?

1 个答案:

答案 0 :(得分:0)

您的代码适用于socket.io@0.9.x,并且您已安装版本1.0或更高版本。您需要降级(npm install socket.io@0.9.17),或者最好是upgrade your codebase to use latest version