-
-
Save hamzamu/9af96e3186d5a1fc08e2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment