forked from koajs/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
44 lines (32 loc) · 665 Bytes
/
app.js
File metadata and controls
44 lines (32 loc) · 665 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const Koa = require('koa');
const koaBody = require('koa-body');
const session = require('koa-session');
const CSRF = require('koa-csrf');
const router = require('koa-router')();
const app = module.exports = new Koa();
/**
* csrf need session
*/
app.keys = ['session key', 'csrf example'];
app.use(session(app));
app.use(koaBody());
/**
* maybe a bodyparser
*/
/**
* csrf middleware
*/
app.use(new CSRF());
/**
* route
*/
router.get('/token', token)
.post('/post', post);
app.use(router.routes());
async function token(ctx) {
ctx.body = ctx.csrf;
}
async function post(ctx) {
ctx.body = {ok: true};
}
if (!module.parent) app.listen(3000);