Last active
December 17, 2015 20:39
-
-
Save craftgear/5669101 to your computer and use it in GitHub Desktop.
expressでミドルウェアもしくはイベントハンドラでセッションの値を参照する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//ミドルウェアでやる場合 | |
app.configure(function(){ | |
//・・・(略)・・・ | |
app.use(function (req, res, next) { | |
app.locals.message = req.session.message; | |
next(); | |
}); | |
//・・・(略)・・・ | |
}); | |
//イベントハンドラでやる場合 | |
app.post('/hoge', function(req, res){ | |
res.locals.message = req.session.username; | |
res.render('hoge'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment