Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// access log
if (me.writeAccessLog()) {
app.use(me._createAccessLogger());
}
// session support
app.use(session({
store: me._getSessionStore()
}));
// csrf support
if (me._enableCSRF === true) {
var csrf = require('koa-csrf');
csrf(app);
app.use(csrf.middleware);
}
// parse url query string and body before any middleware defined by user is running
qs(app, 'first'); // /foo?a=b&a=c this.query.a = 'b' , not a = ['b', 'c']
// support multipart-form-data
me._createMultipartMiddleware(app);
// default middlewares
me._createDefaultMiddlewares(app);
// user defined middlewares
me._createExtraMiddlewares(app);
// inner routes
me._createDefaultRoutes(app);
var koa = require('koa');
var csrf = require('koa-csrf');
var session = require('koa-session');
var bodyParser = require('koa-bodyparser');
var router = require('koa-router')();
var app = koa();
app.use(bodyParser());
app.keys = ['session secret'];
app.use(session(app));
csrf(app);
app.use(csrf.middleware);
router.get('/form', function *() {
// pass the csrfToken to the view
var html =
'' +
'' +
'' +
'' +
'<title>Document</title>' +
'' +
'' +
'<form method="POST" action="/process">' +
'<input value="' + this.csrf + '" name="_csrf" type="hidden">' +
'Favorite color: <input name="favoriteColor" type="text">' +
'<button type="submit">Submit</button>' +
'</form>' +