public-address
Advanced tools
Comparing version 0.1.0 to 0.1.1
37
index.js
@@ -1,8 +0,8 @@ | ||
"use strict"; | ||
'use strict'; | ||
var http = require("http"); | ||
var http = require('http'); | ||
module.exports = resolve; | ||
function resolve(options, callback){ | ||
function resolve(options, callback) { | ||
var requestOptions = { | ||
@@ -15,3 +15,3 @@ hostname: 'www.remoteaddress.net', | ||
if(!callback && typeof options == "function"){ | ||
if (!callback && typeof options == 'function') { | ||
callback = options; | ||
@@ -22,3 +22,3 @@ options = undefined; | ||
options = options || {}; | ||
Object.keys(options).forEach(function(key){ | ||
Object.keys(options).forEach(function(key) { | ||
requestOptions[key] = options[key]; | ||
@@ -28,8 +28,9 @@ }); | ||
http.get(requestOptions, function(res) { | ||
var chunks = [], chunklen = 0; | ||
var chunks = [], | ||
chunklen = 0; | ||
if(res.statusCode != 200){ | ||
res.on("data", function(){}); | ||
res.on("end", function(){ | ||
callback(new Error("Invalid response code " + res.statusCode)); | ||
if (res.statusCode != 200) { | ||
res.on('data', function() {}); | ||
res.on('end', function() { | ||
callback(new Error('Invalid response code ' + res.statusCode)); | ||
}); | ||
@@ -39,3 +40,3 @@ return; | ||
res.on("data", function(chunk){ | ||
res.on('data', function(chunk) { | ||
chunks.push(chunk); | ||
@@ -45,10 +46,10 @@ chunklen += chunk.length; | ||
res.on("end", function(){ | ||
res.on('end', function() { | ||
var data; | ||
try{ | ||
try { | ||
data = JSON.parse(Buffer.concat(chunks, chunklen).toString()); | ||
}catch(exception){} | ||
if(!data){ | ||
callback(new Error("Invalid response from server")); | ||
}else{ | ||
} catch (exception) {} | ||
if (!data) { | ||
callback(new Error('Invalid response from server')); | ||
} else { | ||
callback(null, data); | ||
@@ -60,2 +61,2 @@ } | ||
}); | ||
} | ||
} |
{ | ||
"name": "public-address", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Resolve public IP address and hostname", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
1
2940
46