当我运行以下js代码
时var express = require("express"),
exp = express(),
http= require('http');
var app = http.createServer(exp),
io = require('socket.io').listen(app);
// io = require('socket.io')(app);
var redis = require("redis"),
rclient = redis.createClient();
app.listen(8080);
//app.use("/static", express.static(__dirname + '/static'));
app.configure(function() {
app.use("/static", express.static(__dirname + '/static'));
})
app.get('/', function (req, res) {
res.sendfile(__dirname + '/index.html');
});
var board_sockets = {};
io.sockets.on('connection', function (socket) {
var board_id = socket.handshake.query.board_id;
if(!board_sockets[board_id]) board_sockets[board_id] = [];
// TODO: Do something if the board_id is undefined
board_sockets[board_id].push(socket);
var redis_key = "board_" + board_id;
rclient.lrange(redis_key, 0, -1, function(err, res) {
socket.emit('board_state', res);
});
socket.on('update', function (data) {
for(idx in board_sockets[board_id]) {
var s = board_sockets[board_id][idx];
if(s != socket) {
s.emit('update', data);
data.timestamp = Math.round(new Date().getTime() / 1000);
rclient.lpush(redis_key, JSON.stringify(data));
}
}
});
});
我收到了这个错误 object#server没有方法' configure'
答案 0 :(得分:1)
在您的示例中,app
是http.Server
class的一个实例,其原型中确实既没有.configure
也没有.use
。
您可能打算写exp.use(...)
而不是app.use(...)
。
顺便说一句,自{3.1}版快递以来app.configure
已被弃用,自快递4.0.0以来已完全删除。