Created
January 27, 2014 07:07
-
-
Save drobune/8644254 to your computer and use it in GitHub Desktop.
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.set('views', __dirname + '/views'); | |
app.set('view engine', 'jade'); | |
app.use(express.cookieParser()); | |
//↓sessionの前に書かないと、最初のアクセスでundefinedが返ってきました。 | |
app.use(express.csrf()); | |
app.use(express.session({ secret: 'secret goes here' })); | |
app.use(express.bodyParser()); | |
app.use(app.router); | |
app.use(express.static(__dirname + '/public')); | |
}); | |
//tokenを作るメソッド | |
function csrf(req, res, next) { | |
//localsがexpress version3以降のhelperです。 | |
res.locals.token = req.session._csrf; | |
next(); | |
} | |
//第二引数にcsrfメソッドを書きます。 | |
app.get('/', csrf, function(req, res) { | |
res.render('index'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment