javascript - node express: mock authorize function in app.get -


i'm practicing simple .get methods in node/express. i'm following example of book, have no session variable , have no templates; i've commented lines , i've replaced them simple .send method, , i've replaced simple hardcode variable: authorized.

i'm getting error: referenceerror: res not defined

the problem have no res variable, because control pass first on authorize function.

function authorize(req, res, next){     authorized = true;     // if(req.session.authorized) return next();     if(authorized) return next();     res.send('not-authorized'); } app.get('/secret', authorize, function(){     // res.render('secret');     res.send('secret'); }); app.get('/sub-rosa', authorize, function(){     // res.render('sub-rosa');     res.send('sub-rosa'); }); 

thanks comments, solution is:

function authorize(req, res, next){     authorized = true;     // if(req.session.authorized) return next();     if(authorized) return next();     res.send('not-authorized'); } app.get('/secret', authorize, function( req, res ){     // res.render('secret');     res.send('secret'); }); app.get('/sub-rosa', authorize, function( req, res ){     // res.render('sub-rosa');     res.send('sub-rosa'); }); 

Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -