Express.js在使用会话时没有响应

时间:2012-06-24 00:04:22

标签: node.js session redis express

这是我的应用:

var express = require('express'),
    app = express.createServer(),
    RedisStore = require('connect-redis')(express);

app.configure (function(){
    app.use (express.logger({ format: ":method :url" }));
    app.use (express.bodyParser());
    app.use (express.cookieParser());
    app.use (express.session({ store: new RedisStore, secret: "totally random string" }));
});
app.configure ('development', function () {
    console.log ("Development mode.");
});
app.configure ('production', function () {
    console.log ("Production mode.");
});

app.get ('/', function (req, res) {
    res.contentType("text/html");
    res.send("hello", 200);
    res.end();
})

console.log ("Listening to *:"+8006);
app.listen (8006);

当我使用localhost:8006 /

时,它会在浏览器中挂起

任何想法都错了吗?我可能错过了一点细节 当app.use (express.session...行被注释掉时它会起作用

由于

1 个答案:

答案 0 :(得分:3)

删除res.end(),它会停止挂起并呈现页面。

var express = require('express'),
    app = express.createServer();

app.configure (function(){
    app.use (express.logger({ format: ":method :url" }));
    app.use (express.bodyParser());
    app.use (express.cookieParser());
});

app.configure ('development', function () {
    console.log ("Development mode.");
});
app.configure ('production', function () {
    console.log ("Production mode.");
});

app.get ('/', function (req, res) {
    res.contentType("text/html");
    res.send("hello");
})

console.log ("Listening to *:"+8006);
app.listen (8006);