Created
August 15, 2014 01:30
-
-
Save grawk/af976c29fedfb6602db1 to your computer and use it in GitHub Desktop.
krakenjs/lusca express4 example app
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
'use strict'; | |
var express = require('express'), | |
cookieParser = require('cookie-parser'), | |
session = require('cookie-session'), | |
bodyParser = require('body-parser'), | |
errorHandler = require('errorhandler'), | |
lusca = require('./index'), | |
h = ['<html><head><title>views</title></head><body><h1>', '</h1><form method="POST" action="/"><input type="hidden" name="_csrf" value="', '"/><input type="submit" value="Submit"/></form></body></html>'], | |
app = express(); | |
app.use(cookieParser()); | |
app.use(session({ | |
secret: 'abc' | |
})); | |
app.use(bodyParser.json()); | |
app.use(bodyParser.urlencoded({ | |
extended: false | |
})); | |
app.use(lusca({ | |
csrf: true | |
})); | |
app.use(errorHandler()); | |
app.get('/', function(req, res) { | |
res.status(200).send(h[0] + res.locals._csrf + h[1] + res.locals._csrf + h[2]); | |
}); | |
app.post('/', function(req, res) { | |
res.status(200).send(h[0] + res.locals._csrf + h[1] + res.locals._csrf + h[2]); | |
}); | |
app.listen(3000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment