我正在嘗試使用Express中的會話。我儘可能小心地閱讀了文檔,但在代碼和示例之間找不到任何區別 - 但是,會話似乎沒有初始化。Express中的會話不起作用
這裏是我的app.js
var express = require('express')
, routes = require('./routes')
, customRoutes = require('./routes/custom.js');
var app = module.exports = express.createServer();
// Configuration
app.configure(function(){
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(__dirname + '/public'));
app.use(express.cookieParser());
app.use(express.session({ secret: "keyboard cat" }));
});
app.configure('development', function(){
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});
app.configure('production', function(){
app.use(express.errorHandler());
});
// Routes
app.get('/', function(req, res){
req.session.something = "please?";
req.session.boo = true;
req.session.int = 100;
console.log(req.session); // undefined
});
當我運行它的開始:類型錯誤:無法設置屬性未定義的「東西」。
檢查什麼?
$ npm ls
ââ⬠[email protected]
â âââ [email protected]
â ââ⬠[email protected]
â âââ [email protected]
ââ⬠[email protected]
â âââ [email protected]
â âââ [email protected]
â âââ [email protected]
â âââ [email protected]
âââ [email protected]
請,將問題的名稱改爲有意義的。 – sorin