1var bodyParser = require('body-parser')
2var cookieParser = require('cookie-parser')
3var csrf = require('csurf')
4var express = require('express')
5
6var app = express()
7app.use(bodyParser.urlencoded({ extended: false }))
8app.use(cookieParser())
9app.use(csrf({ cookie: true }))
10
11// error handler
12app.use(function (err, req, res, next) {
13 if (err.code !== 'EBADCSRFTOKEN') return next(err)
14
15 // handle CSRF token errors here
16 res.status(403)
17 res.send('form tampered with')
18})
19