hapi-io
hapi-io copied to clipboard
Cant get it working with 'socket.io-redis'
Hi @sibartlett ,
I'm using PM2 with -i max to run my app as cluster but the initial handshake fails. There is a solution which is http://socket.io/docs/using-multiple-nodes/ by using 'socket.io-redis'
var io = require('socket.io')(3000);
var redis = require('socket.io-redis');
io.adapter(redis({ host: 'localhost', port: 6379 }));
Just tried to do something like this on server.register
callback:
var io = server.plugins['hapi-io'].io;
var redis = require('socket.io-redis');
io.adapter(redis({ host: 'localhost', port: 6379 }));
But didn't work. Any suggestion?
I have the same problem, I use a cluster of hapi server and I need redis to redispatch to the corect server/client the events.
Anyone able to get this working?
You need to add the adapter to the plugin config, something like the this:
import HapiIO from 'hapi-io';
import ioRedis from 'socket.io-redis';
...
{
register: HapiIO,
options: {
socketio: {
adapter: ioRedis({
host: process.env.REDIS_HOST,
port: process.env.REDIS_PORT,
}),
},
},
},
...