Skip to content

Instantly share code, notes, and snippets.

@zlatkov
Last active February 8, 2021 14:11
Show Gist options
  • Save zlatkov/4716b1ff10bfef3c55b23165c7aa9adc to your computer and use it in GitHub Desktop.
Save zlatkov/4716b1ff10bfef3c55b23165c7aa9adc to your computer and use it in GitHub Desktop.
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