-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.js
35 lines (28 loc) · 840 Bytes
/
example.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
'use strict';
const Koa = require('koa');
const session = require('.');
const MemcachedStore = require('killara-memcached');
const phpserialize = require('php-serialize');
const app = new Koa();
const CONFIG = {
key: 'hexindai-session', // cookie key
store: new MemcachedStore({
serialize: phpserialize.serialize,
unserialize: phpserialize.unserialize,
}),
expire_on_close: false,
lifetime: 30, // minites, the same as maxAge
cipherKey: 'base64:PmneUUljyYy+Ynyv9HCIjPvMicZoamVpnSUsf2RtKsE=',
cipherAlgorithm: 'AES-256-CBC',
prefix: 'laravel:',
};
app.use(session(app, CONFIG));
app.use(ctx => {
// demo ignore favicon
if (ctx.path === '/favicon.ico') return;
let n = ctx.session.hits || 0;
ctx.session.hits = ++n;
ctx.body = n + ' hits';
});
app.listen(3000);
console.log('listening on port 3000');