I've seen several posts related to this but none solved my problem.
I have this code in server.js
var express = require('express');
var app = express();
app.configure(function(){
app.set(express.cookieParser());
app.set(express.session({secret: "This is a secret"}));
});
app.get('/name/:name', function(req, res){
req.session.name = req.params.name;
res.send("<a href='/name'>GO</a>");
});
app.get('/name', function(req, res){
res.send(req.session.name);
});
app.listen(3000);
When I go to http://localhost:3000/user/someone
that's the output that I get
TypeError: Cannot set property 'name' of undefined at /Users/Me/Node/server.js:10:19 at callbacks
I've seen several posts related to this but none solved my problem.
I have this code in server.js
var express = require('express');
var app = express();
app.configure(function(){
app.set(express.cookieParser());
app.set(express.session({secret: "This is a secret"}));
});
app.get('/name/:name', function(req, res){
req.session.name = req.params.name;
res.send("<a href='/name'>GO</a>");
});
app.get('/name', function(req, res){
res.send(req.session.name);
});
app.listen(3000);
When I go to http://localhost:3000/user/someone
that's the output that I get
TypeError: Cannot set property 'name' of undefined at /Users/Me/Node/server.js:10:19 at callbacks
-
1
wasn't that
app.use(express.cookieParser())
, etc? – Michael Krelin - hacker Commented Oct 26, 2013 at 15:29 -
1
(also, I think
app.configure
is not needed and only kept as legacy, you should just callapp.use(stuff)
). – Michael Krelin - hacker Commented Oct 26, 2013 at 15:31 -
The
app.configure()
method is not legacy, and neither is it used incorrectly here. The issue here is that the person who asked the question is using the method used to set settings rather than the method to apply middleware. – hexacyanide Commented Oct 26, 2013 at 19:06 - The docs seem to suggest it's legacy... – robertklep Commented Oct 26, 2013 at 19:21
1 Answer
Reset to default 3Decided to copy from ments. Try replacing
app.configure(function(){
app.set(express.cookieParser());
app.set(express.session({secret: "This is a secret"}));
});
with
app.use(express.cookieParser());
app.use(express.session({secret: "This is a secret"}));
and see what happens.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745580054a4634200.html
评论列表(0条)