Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using redisStore for session storage #144

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ pids
*.pid
*.seed

# Redis dumps
dump.rdb

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@
"body-parser": "^1.10.2",
"bower": "^1.3.12",
"cloudinary": "^1.1.1",
"connect-redis": "^2.2.0",
"cookie-parser": "^1.3.3",
"express": "^4.11.1",
"express-jwt": "^1.0.0",
"express-session": "^1.10.1",
"gulp": "^3.8.10",
"gulp-compass": "~2.0.3",
"gulp-coveralls": "^0.1.3",
"gulp-concat": "^2.4.3",
"gulp-coveralls": "^0.1.3",
"gulp-exit": "0.0.2",
"gulp-image": "^0.5.3",
"gulp-istanbul": "^0.5.0",
Expand All @@ -63,6 +64,7 @@
"passport-facebook": "^1.0.3",
"passport-local": "^1.0.0",
"passport-twitter": "^1.0.2",
"redis": "^0.12.1",
"run-sequence": "^1.0.2",
"url-to-screenshot": "^0.6.0"
},
Expand Down
5 changes: 5 additions & 0 deletions server/config/environment/development.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,10 @@ module.exports = {
uri: 'mongodb://localhost/archivr-dev'
},

redis: {
hostname: '127.0.0.1',
port: 6379
},

seedDB: true
};
12 changes: 12 additions & 0 deletions server/config/environment/production.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

// Production specific configuration
// =================================

// Parse RedisCloud environment variable
var url = require('url');
var redisURL = url.parse(process.env.REDISCLOUD_URL || '');

module.exports = {
// Server IP
ip: process.env.OPENSHIFT_NODEJS_IP ||
Expand All @@ -19,5 +24,12 @@ module.exports = {
process.env.MONGOHQ_URL ||
process.env.OPENSHIFT_MONGODB_DB_URL+process.env.OPENSHIFT_APP_NAME ||
'mongodb://localhost/archivr'
},

// Redis connection options
redis: {
hostname: redisURL.hostname || '127.0.0.1',
port: redisURL.port || 6379,
auth: redisURL.auth ? redisURL.auth.split(':')[1] : undefined
}
};
24 changes: 18 additions & 6 deletions server/config/express.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ var bodyParser = require('body-parser');
var morgan = require('morgan');
var config = require('./environment');
var session = require('express-session');
var RedisStore = require('connect-redis')(session);
var redis = require('redis');
var url = require('url');

// Configure Redis server
var redisClient = redis.createClient(config.redis.port, config.redis.hostname,
{ no_ready_check: true }); // jshint ignore:line
if (config.redis.auth) redisClient.auth(config.redis.auth);

module.exports = function expressConfig(app) {
// standard POST request body parser
Expand All @@ -14,6 +22,16 @@ module.exports = function expressConfig(app) {
// HTTP request logger middleware
app.use(morgan('combined'));

app.use(session({
// Use RedisStore for session storage
store: new RedisStore({
client: redisClient
}),
secret: config.expressSessionSecret,
resave: false,
saveUninitialized: true
}));

// set view directory
app.set('views', __dirname + '/../views');

Expand All @@ -23,12 +41,6 @@ module.exports = function expressConfig(app) {
// set static asset dir
app.use(express.static(__dirname + '/../../client/app/dist'));

app.use(session({
secret: config.expressSessionSecret,
resave: false,
saveUninitialized: true
}));

// dynamically set port if in production otherwise use port 3000
app.set('port', config.port);
app.set('jwtTokenSecret', config.jwtTokenSecret);
Expand Down