Last active
February 8, 2021 14:11
-
-
Save zlatkov/4716b1ff10bfef3c55b23165c7aa9adc to your computer and use it in GitHub Desktop.
This file contains hidden or 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 express = require('express'); | |
const bodyParser = require('body-parser'); | |
const csrf = require('csurf') | |
const cookieParser = require('cookie-parser') | |
const app = express(); | |
const csrfProtection = csrf({ cookie: true }); | |
app.use(cookieParser()); | |
app.use(bodyParser.urlencoded({ extended: true })); | |
app.set('view engine', 'ejs'); | |
app.get('/', csrfProtection, (req, res) => { | |
res.render('index', { csrfToken: req.csrfToken() }); | |
}); | |
app.post('/profile', csrfProtection, (req, res, next) => { | |
res.send(req.body.name); | |
}); | |
app.listen(3000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment