Skip to content
Myr

redis.js

This file

Path

examples/session/redis.js

37 lines · 943 bytes · JavaScript

Last changed by

deps: update example dependenciesDouglas Christopher Wilsonbefore adoptionca306ea

History of this file

Take it

The walk stopped after 200 commits: lines older than f41d09a point at it.

Merge pull request #2008 from agchou/clean-up-codeJonathan Ongbefore adoption2e830ff

lines 1–3why, one step back
1/**
2 * Module dependencies.3 */

remove app.router and refactor middleware processingRoman Shtylmanbefore adoptionf41d09a

lines 4–5why, one step back
4
5var express = require('../..');

fix examples for express 4 (separate middleware)Roman Shtylmanbefore adoptionf1315b9

lines 6–7why, one step back
6var logger = require('morgan');
7var session = require('express-session');

remove app.router and refactor middleware processingRoman Shtylmanbefore adoptionf41d09a

lines 8–9why, one step back
8
9// pass the express to the connect redis module

fix examples for express 4 (separate middleware)Roman Shtylmanbefore adoptionf1315b9

lines 10–11why, one step back
10// allowing it to inherit from session.Store
11var RedisStore = require('connect-redis')(session);

remove app.router and refactor middleware processingRoman Shtylmanbefore adoptionf41d09a

lines 12–14why, one step back
12
13var app = express();14

fix examples for express 4 (separate middleware)Roman Shtylmanbefore adoptionf1315b9

line 15why, one step back
15app.use(logger('dev'));

remove app.router and refactor middleware processingRoman Shtylmanbefore adoptionf41d09a

lines 16–17why, one step back
16
17// Populates req.session

deps: update example dependenciesDouglas Christopher Wilsonbefore adoptionca306ea

lines 18–23why, one step back
18app.use(session({
19 resave: false, // don't save session if unmodified20 saveUninitialized: false, // don't create session until something stored21 secret: 'keyboard cat',22 store: new RedisStore23}));

remove app.router and refactor middleware processingRoman Shtylmanbefore adoptionf41d09a

lines 24–37why, one step back
24
25app.get('/', function(req, res){26 var body = '';27 if (req.session.views) {28 ++req.session.views;29 } else {30 req.session.views = 1;31 body += '<p>First time visiting? view this page in several browsers :)</p>';32 }33 res.send(body + '<p>viewed <strong>' + req.session.views + '</strong> times.</p>');34});3536app.listen(3000);37console.log('Express app started on port 3000');