CSRF Tokens Middleware for Trek.js
$ npm install trek-csrf --save
'use strict'
const Engine = require('trek-engine')
const sessions = require('trek-sessions')
const bodyParser = require('trek-body-parser')
const csrf = require('trek-csrf')
async function start () {
const app = new Engine()
app.use(sessions())
app.use(bodyParser())
app.use(csrf())
app.use(ctx => {
ctx.res.body = ctx.store.get('csrf')
})
app.on('error', (err, ctx) => {
console.log(err)
})
app.run(3000)
}
start().catch(console.log)
csrf({
key: 'csrf',
tokenLookup: 'header:X-CSRF-Token',
ignoreMethods: ['GET', 'HEAD', 'OPTIONS', 'TRACE'],
// https://github.com/pillarjs/csrf#new-tokensoptions
tokenOptions: undefined
})