-
Notifications
You must be signed in to change notification settings - Fork 0
/
app1.js
46 lines (40 loc) · 916 Bytes
/
app1.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
var session = require('koa-generic-session');
var redisStore = require('koa-redis');
var koa = require('koa');
var app = koa();
app.keys = ['keys', 'keykeys'];
app.use(session({
store: redisStore()
}));
app.use(function* () {
console.log(this.path);
switch (this.path) {
case '/get':
get.call(this);
break;
case '/remove':
remove.call(this);
break;
case '/regenerate':
yield regenerate.call(this);
break;
}
});
function get() {
var session = this.session;
session.count = session.count || 0;
session.count++;
this.body = session.count;
}
function remove() {
this.session = null;
this.body = 0;
}
function* regenerate() {
get.call(this);
yield this.regenerateSession();
get.call(this);
}
var port = 8080;
app.listen(port);
console.log('server listen at ' + port);