Skip to content
This repository was archived by the owner on Feb 12, 2026. It is now read-only.

Commit 2341424

Browse files
authored
Merge pull request #4 from SpringRole/DM-2
update the function and handle error
2 parents 226b82b + dcd124e commit 2341424

3 files changed

Lines changed: 23 additions & 15 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ This module help you to verify domain ownership.
2020
Verify by uploading a specific HTML to a given domain.
2121

2222
### Parameters:
23-
* domain_url: The URL where the html file can be formed.
23+
* domain_url: The URL where the html file can be formed (http://example.com).
2424
* domain_html_name: The name of the html file expected at 'domain_url'
2525
* hash_value: The value in the html file body
2626

index.js

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ var metafetch = require('metafetch');
44
var request = require('request');
55
var Promise = require("bluebird");
66
var dns = require("dns");
7+
var parser = require('getdomain');
78

89
var DomainVerification = (function() {
910

@@ -14,7 +15,7 @@ var DomainVerification = (function() {
1415
if(original_args.length == 3)
1516
{
1617
var obj = {};
17-
obj.verified = "Html Verification";
18+
obj.verified = "htmlVerification";
1819
var url = domain_url+'/'+domain_html_name+'.html';
1920
var options = {
2021
method: 'GET',
@@ -47,25 +48,31 @@ var DomainVerification = (function() {
4748
return new Promise(function (resolve,reject){
4849
if(original_args.length == 3){
4950
var obj = {};
50-
obj.verified = "Txt Verification";
51-
dns.resolveTxt(domain_url, function(error,records){
51+
obj.verified = "txtVerification";
52+
var domain = parser.hostname(domain_url);
53+
dns.resolveTxt(domain, function(error,records){
5254
if(records == undefined)
5355
{
5456
obj.status = false;
5557
resolve(obj);
5658
} else {
59+
var success = [];
60+
var expected = domain_key+'='+domain_value;
5761
records.forEach(function(record){
58-
var expected = domain_key+'='+domain_value;
5962
if(expected == record[0])
6063
{
61-
obj.status = true;
62-
resolve(obj);
63-
}
64-
else {
65-
obj.status = false;
66-
resolve(obj);
67-
}
64+
success.push(obj.status);
65+
}
6866
});
67+
68+
if(success.length > 0)
69+
{
70+
obj.status = true;
71+
resolve(obj);
72+
} else {
73+
obj.status = false;
74+
resolve(obj);
75+
}
6976
}
7077
});
7178
}
@@ -79,7 +86,7 @@ var DomainVerification = (function() {
7986
var original_args = arguments;
8087
return new Promise(function(resolve,reject){
8188
var obj = {};
82-
obj.verified = "Meta tag Verification";
89+
obj.verified = "metaTagVerification";
8390

8491
if(original_args.length == 3)
8592
{
@@ -129,9 +136,9 @@ var DomainVerification = (function() {
129136
results_data.forEach( data=>{
130137
if(data.status)
131138
{
132-
success.push(data.name);
139+
success.push(data.verified);
133140
} else {
134-
failure.push(data.name);
141+
failure.push(data.verified);
135142
}
136143
});
137144
if(success.length > 0)

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
},
1313
"dependencies": {
1414
"bluebird": "^3.5.1",
15+
"getdomain": "^1.3.0",
1516
"metafetch": "^1.8.1",
1617
"request": "^2.87.0"
1718
},

0 commit comments

Comments
 (0)