我正在尝试与节点进行一些会话身份验证。当我在本地主机上运行它时,这段代码工作正常但在远程服务器上没有检索到会话。
每次点击远程服务器时,我都会看到生成了一个新的会话ID,而它在localhost上保持不变。
请注意,我通过ip地址直接访问URL(没有客户端JS)。问题最初出现在expressJS / jquery中,但我设法使用以下代码重现:
var express = require('express');
var app = express.createServer();
app.configure(function(){
app.use(express.bodyParser());
app.use(express.cookieParser());
app.use(express.session({ secret: "keyboard cat" }));
app.use(app.router);
});
app.get('/login', function(req, res){
// Perhaps we posted several items with a form
// (use the bodyParser() middleware for this)
req.session.loggedIn = true;
var msg = "You are logged In. SessionId:"+req.session.id;
console.log(msg);
res.end(msg);
});
app.get('/isLoggedIn', function(req, res){
var msg = "isLoggedIn: "+req.session.loggedIn+" SessionId:"+req.session.id;
console.log(msg);
res.end(msg);
});
app.get('/logout', function(req, res){
req.session.destroy();
var msg = "Logged out";
console.log(msg);
res.end(msg);
});
app.listen(3000);
你知道可能出现什么问题吗?
节点:v0.4.12 connect:v1.7.1
谢谢, - 尼古拉斯