I used this at the beginning:
var app = express.createServer(
express.cookieParser(),
express.session({ secret: 'somesecretword' })
);
Below code is an example code to get user data with uname as key.
I call this code from the baseline URL by calling model.fetch ().
app.get('/user/:uname/', function (req, res) {
var uname=req.params.uname;
if(!req.session.user)
res.send("Not Logged In");
return UserModel.find({uname : uname},function(err, user) {
if (!err) {
return res.send(user);
} else {
return res.send(err);
}
});
});
So, here I wrote the code to verify the session directly in the get method above.
What if I have many such methods? Do I have to write the same thing in every method, or is there any controller in Node that does this?
For example, show me a controller that checks the paths / user, means that / user / anythinghere / should be checked automatically or show me another better way.
source
share