From 38e7106bdab7ad792fef0aa67f7f997cbefea0dc Mon Sep 17 00:00:00 2001 From: Rupam Biswal Date: Mon, 9 Jul 2018 15:11:41 +0530 Subject: [PATCH 1/2] update the function and handle error --- README.md | 2 +- index.js | 37 ++++++++++++++++++++++--------------- package.json | 1 + 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 79cb6de..e50dab1 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ This module help you to verify domain ownership. Verify by uploading a specific HTML to a given domain. ### Parameters: - * domain_url: The URL where the html file can be formed. + * domain_url: The URL where the html file can be formed (http://example.com). * domain_html_name: The name of the html file expected at 'domain_url' * hash_value: The value in the html file body diff --git a/index.js b/index.js index da8b9ff..928eb4f 100644 --- a/index.js +++ b/index.js @@ -4,6 +4,7 @@ var metafetch = require('metafetch'); var request = require('request'); var Promise = require("bluebird"); var dns = require("dns"); +var parser = require('getdomain'); var DomainVerification = (function() { @@ -14,7 +15,7 @@ var DomainVerification = (function() { if(original_args.length == 3) { var obj = {}; - obj.verified = "Html Verification"; + obj.verified = "htmlVerification"; var url = domain_url+'/'+domain_html_name+'.html'; var options = { method: 'GET', @@ -47,25 +48,31 @@ var DomainVerification = (function() { return new Promise(function (resolve,reject){ if(original_args.length == 3){ var obj = {}; - obj.verified = "Txt Verification"; - dns.resolveTxt(domain_url, function(error,records){ + obj.verified = "txtVerification"; + var domain = parser.hostname(domain_url); + dns.resolveTxt(domain, function(error,records){ if(records == undefined) { obj.status = false; resolve(obj); } else { + var success = []; + var expected = domain_key+'='+domain_value; records.forEach(function(record){ - var expected = domain_key+'='+domain_value; if(expected == record[0]) { - obj.status = true; - resolve(obj); - } - else { - obj.status = false; - resolve(obj); - } + success.push(obj.status); + } }); + + if(success.length > 0) + { + obj.status = true; + resolve(obj); + } else { + obj.status = false; + resolve(obj); + } } }); } @@ -79,7 +86,7 @@ var DomainVerification = (function() { var original_args = arguments; return new Promise(function(resolve,reject){ var obj = {}; - obj.verified = "Meta tag Verification"; + obj.verified = "metaTagVerification"; if(original_args.length == 3) { @@ -129,9 +136,9 @@ var DomainVerification = (function() { results_data.forEach( data=>{ if(data.status) { - success.push(data.name); + success.push(data.verified); } else { - failure.push(data.name); + failure.push(data.verified); } }); if(success.length > 0) @@ -143,7 +150,7 @@ var DomainVerification = (function() { obj.verified = []; } resolve(obj); - }).catch( error =>{ + }).catch( error =>{ console.log('err',error); reject(error); }); } else { diff --git a/package.json b/package.json index 8687dc7..0c6ec48 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ }, "dependencies": { "bluebird": "^3.5.1", + "getdomain": "^1.3.0", "metafetch": "^1.8.1", "request": "^2.87.0" }, From dcd124e4ab2f03aa4f8d0f49cfeacc64b8eba35b Mon Sep 17 00:00:00 2001 From: Rupam Biswal Date: Mon, 9 Jul 2018 15:15:11 +0530 Subject: [PATCH 2/2] remove console log --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 928eb4f..a2d3604 100644 --- a/index.js +++ b/index.js @@ -150,7 +150,7 @@ var DomainVerification = (function() { obj.verified = []; } resolve(obj); - }).catch( error =>{ console.log('err',error); + }).catch( error =>{ reject(error); }); } else {