Created
March 29, 2019 12:40
-
-
Save desaijay315/fc9a5709ed6ce27c42d9ede70efb260d 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
const cookieParser = require('cookie-parser'); | |
const csrf = require('csurf'); | |
const bodyParser = require('body-parser'); | |
const express = require('express'); | |
const csrfProtection = csrf({ cookie: true }); | |
const parseForm = bodyParser.urlencoded({ extended: false }); | |
const app = express(); | |
// parse cookies | |
// we need this because "cookie" is true in csrfProtection | |
app.use(cookieParser()); | |
app.get('/form', csrfProtection, function (req, res) { | |
// pass the csrfToken to the view | |
res.render('send', { csrfToken: req.csrfToken() }) | |
}) | |
app.post('/process', parseForm, csrfProtection, function (req, res) { | |
res.send('data is being processed') | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment