UNPKG

1.81 kBJavaScriptView Raw
1var kick = require('../kick')
2 , http = require('http')
3 , profiler = require('v8-profiler')
4 , connect = require('connect')
5 , redisClient = require('redis').createClient()
6 , RedisStore = require('connect-redis')(connect);
7
8var app = module.exports = kick();
9
10app.use(connect.cookieParser('secret'));
11
12var connectSession = connect.session({ store: new RedisStore, secret: 'keyboard cat' })
13
14var kickSession = function(req, res, next) {
15 redisClient.hgetall('sess:foo', function(err, data){
16 req.session = data || {}
17 next(err)
18 })
19}
20
21app.get('/set-connect-session', connectSession, function(req, res) {
22 if(!req.session) {
23 res.writeHead(500)
24 res.end()
25 } else {
26 req.session.username = 'username'
27 res.end()
28 }
29})
30
31app.get('/get-connect-session', connectSession, function(req, res) {
32 if(!req.session) {
33 res.writeHead(500)
34 res.end()
35 } else {
36 res.end(req.session.username)
37 }
38})
39
40app.get('/set-kick-session', kickSession, function(req, res) {
41 req.session.username = 'foo username'
42 res.end()
43})
44
45app.get('/get-kick-session', kickSession, function(req, res) {
46 res.end('' + req.session)
47})
48
49app.get('/', function(req, res){
50 res.end()
51})
52
53// setInterval(function(){
54// profiler.startProfiling('flow');
55// setTimeout(function(){
56// profiler.stopProfiling('flow');
57// }, 500)
58// }, 1000)
59
60var ServerResponse = http.ServerResponse;
61var rawEnd = ServerResponse.prototype.end;
62console.log(ServerResponse)
63console.log(rawEnd)
64
65// ServerResponse.prototype.end = function() {
66// rawEnd.apply(this, [].slice.call(arguments))
67// profiler.stopProfiling('flow');
68// }
69
70if(!module.parent) {
71 http.createServer(function(req, res){
72 // profiler.startProfiling('flow');
73 app(req, res);
74 }).listen(3000);
75}
76