Created
August 22, 2014 09:48
-
-
Save octavian-nita/fd3cdb4a27964c8d2c08 to your computer and use it in GitHub Desktop.
Callback on getting the current visible IP address in Node.js, using basic proxy authorization
This file contains hidden or 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
| 'use strict'; | |
| var ip; | |
| function visibleIp(callback) { | |
| if (ip || (ip = process.env['VISIBLE_IP'])) { | |
| return process.nextTick(function() { callback(null, ip); }); | |
| } | |
| require('http').get({ | |
| host: 'proxyHost', | |
| port: proxyPort, | |
| path: 'http://cp.vu/show_my_ip', | |
| headers: { | |
| 'Proxy-Authorization': 'Basic ' + new Buffer('username:password').toString('base64'), | |
| Host: 'cp.vu' | |
| }}, function(response) { | |
| ip = ''; | |
| response.on('data', function(chunk) { ip += chunk; }); | |
| response.on('end', function() { callback(null, ip); }); | |
| }).on('error', function(error) { callback(error); }).end(); | |
| } | |
| exports.visibleIp = visibleIp; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment