-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
52 lines (36 loc) · 935 Bytes
/
index.js
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
45
46
47
48
49
50
51
52
'use strict';
const Koa = require('koa');
const svgCaptcha = require('svg-captcha');
const session = require('koa-session');
const app = new Koa();
app.keys = ['some secret hurr'];
app.use(session({
key: 'koa:sess'
}, app));
// app.use(async ctx => {
// ctx.body = 'Hello World';
// });
// app.use(async ctx => {
// const captcha = svgCaptcha({
// width: 200,
// height: 400,
// background: 'black'
// });
// ctx.session.captcha = captcha.text;
// ctx.res.type = 'image/svg+xml';
// ctx.res.status = 200;
// ctx.body = captcha.data;
// });
app.use(async ctx => {
const captcha = svgCaptcha.create({
width: 200,
height: 400,
background: 'black'
});
// captcha.generate();
ctx.session.captcha = captcha.text;
ctx.res.type = 'image/svg+xml';
ctx.res.status = 200;
ctx.body = captcha.data;
});
app.listen(8200);