Skip to content

Commit

Permalink
Use x-forwarded-for header to get the caller’s IP address for realtim…
Browse files Browse the repository at this point in the history
…e activity logging, if available
  • Loading branch information
iamigo committed Jan 28, 2017
1 parent e4b7780 commit dd4c73e
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions realtime/setupSocketIO.js
Expand Up @@ -92,18 +92,21 @@ function setupNamespace(io) {
*/
function init(io) {
io.sockets.on('connection', (socket) => {
console.log(socket); // eslint-disable-line no-console
console.log(socket.handshake); // eslint-disable-line no-console
if (logEnabled) {
const toLog = {
starttime: Date.now(),
};
if (socket.handshake.address) {
toLog.ipAddress = socket.handshake.address;
}
if (socket.handshake) {
if (socket.handshake.headers &&
socket.handshake.headers['x-forwarded-for']) {
toLog.ipAddress = socket.handshake.headers['x-forwarded-for'];
} else if (socket.handshake.address) {
toLog.ipAddress = socket.handshake.address;
}

if (socket.handshake.query && socket.handshake.query.p) {
toLog.perspective = socket.handshake.query.p;
if (socket.handshake.query && socket.handshake.query.p) {
toLog.perspective = socket.handshake.query.p;
}
}

extractTokenInfo(socket)
Expand Down

0 comments on commit dd4c73e

Please sign in to comment.