Skip to content

Instantly share code, notes, and snippets.

@iDoMeteor
Created July 3, 2015 11:35
Show Gist options
  • Save iDoMeteor/d30f854c17ce4f871c09 to your computer and use it in GitHub Desktop.
Save iDoMeteor/d30f854c17ce4f871c09 to your computer and use it in GitHub Desktop.
Gets the DDP connections true IP address by analyzing HTTP forwarded count from the Meteor.connection object. Stripped from iDM Connection Log.
Meteor.methods({
// Get the connections *real* IP
getConnectionIP: function () {
// No need to make others wait
this.unblock();
// Locals
var conn = this.connection;
var ipPublic = conn.clientAddress;
var ipSource = conn.httpHeaders['x-forwarded-for'].split(',')[0]
|| ipPublic;
var prox = (process.env.HTTP_FORWARDED_COUNT)
? parseInt(process.env.HTTP_FORWARDED_COUNT)
: 0;
// Determine IP to log
return (prox) ? ipSource : ipPublic;
},
});
UI.registerHelper('currentIp', function () {
return getConnectionIP();
});
@hamzamu
Copy link

hamzamu commented Jul 3, 2015

nice work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment