Skip to content

Instantly share code, notes, and snippets.

@andreialecu
Last active November 4, 2016 14:09
Show Gist options
  • Save andreialecu/28471f2e9b95fd84be77e73aa393aa1c to your computer and use it in GitHub Desktop.
Save andreialecu/28471f2e9b95fd84be77e73aa393aa1c to your computer and use it in GitHub Desktop.
Using deployd with redis
var deployd = require('deployd');
var redisAdapter = require('socket.io-redis');
var redis = require('redis');
// need two client pairs because one is used for socket.io and the other for sessions
// might not be necessary anymore, see https://github.com/socketio/socket.io-redis/issues/90
var pub = redis.createClient(process.env.REDIS_URL);
var sub = redis.createClient(process.env.REDIS_URL, { 'return_buffers': true });
var pub2 = redis.createClient(process.env.REDIS_URL);
var sub2 = redis.createClient(process.env.REDIS_URL);
var server = deployd({
port: process.env.PORT || 1337,
env: process.env.ENV || 'production',
origins: ['http://localhost:5000', ... ], // optional
allowedResponseHeaders: ['ETag'], // optional
allowedRequestHeaders: ['If-None-Match', 'X-App-Id'], // optional
db: {
connectionString: process.env.MONGO_URI,
},
sessions: {
pubClient: pub2,
subClient: sub2,
},
socketIo: {
options: {
//transports: ['websocket'], // optional
},
adapter: redisAdapter({ pubClient: pub, subClient: sub }),
},
});
// start the server
server.listen();
// debug
server.on('listening', function() {
console.log("Server is listening on port: " + (process.env.PORT || 1337));
});
// Deployd requires this
server.on('error', function(err) {
console.error(err);
process.nextTick(function() { // Give the server a chance to return an error
process.exit();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment