Skip to content
This repository has been archived by the owner on Jun 4, 2023. It is now read-only.

Commit

Permalink
server: retrieve remote IP address properly
Browse files Browse the repository at this point in the history
It seems that the IP address shouldn't be retrieved from handshake but
from request. This would be easier if there was any documentation
instead of random StackOverflow questions.
  • Loading branch information
vincentbernat committed Sep 22, 2015
1 parent f1c283f commit de73f99
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/api/socketio/displays.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ var _ = require('lodash'),
// Handle newly arrived clients
function handleNewDisplay(io) {
io.on('connection', function(socket) {
logger.info('new display', socket.handshake.address);
var ip = (socket.handshake.headers || {})['x-forwarded-for'] ||
socket.request.connection.remoteAddress;
logger.info('new display', ip);
socket.on('register', function(data, fn) {

// Handle registration, retrieve the display name or generate a new one.
Expand All @@ -36,9 +38,7 @@ function handleNewDisplay(io) {
.then(function(display) {
var name = display.toJSON().name,
group = display.toJSON().group,
viewport = display.toJSON().viewport,
ip = (socket.handshake.headers || {})['x-forwarded-for'] ||
(socket.handshake.address || {}).address;
viewport = display.toJSON().viewport;

logger.info('registered display', name, ip);
display
Expand Down

0 comments on commit de73f99

Please sign in to comment.