当前位置 : 主页 > 网页制作 > Nodejs >

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

来源:互联网 收集:自由互联 发布时间:2021-06-16
这是我的应用程序: 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.bod
这是我的应用程序:

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 …行被注释掉的时候

谢谢

删除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);
网友评论