Skip to content

Instantly share code, notes, and snippets.

@drobune
Created January 27, 2014 07:07
Show Gist options
  • Save drobune/8644254 to your computer and use it in GitHub Desktop.
Save drobune/8644254 to your computer and use it in GitHub Desktop.
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