@tryghost/domain-validator 1.5.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +1 -1
- package/lib/pro.js +6 -6
- package/lib/request.js +32 -14
- package/package.json +10 -10
package/LICENSE
CHANGED
package/README.md
CHANGED
package/lib/pro.js
CHANGED
|
@@ -150,19 +150,19 @@ _private.isCertificateError = error => /certificate/.test(error.context);
|
|
|
150
150
|
|
|
151
151
|
// Checks a Pro site using the provided details, and returning a responseObject
|
|
152
152
|
module.exports.validate = (proto, subdomain, customdomain, subdirectory, prodomain) => {
|
|
153
|
-
const
|
|
153
|
+
const firstAttemptUrl = _private.buildUrl(proto, customdomain, subdirectory);
|
|
154
154
|
|
|
155
|
-
debug('Validating ' +
|
|
156
|
-
return request.domain(
|
|
155
|
+
debug('Validating ' + firstAttemptUrl);
|
|
156
|
+
return request.domain(firstAttemptUrl)
|
|
157
157
|
.then((result) => {
|
|
158
158
|
debug('Response received');
|
|
159
159
|
return _private.buildResponse(result, proto, subdomain, customdomain, subdirectory, prodomain);
|
|
160
160
|
})
|
|
161
161
|
.catch(() => {
|
|
162
|
-
const
|
|
162
|
+
const secondAttemptUrl = _private.buildUrl('http', customdomain, subdirectory);
|
|
163
163
|
|
|
164
|
-
debug('Validating ' +
|
|
165
|
-
return request.domain(
|
|
164
|
+
debug('Validating ' + secondAttemptUrl);
|
|
165
|
+
return request.domain(secondAttemptUrl)
|
|
166
166
|
.then((result) => {
|
|
167
167
|
debug('HTTP response received');
|
|
168
168
|
const response = _private.buildResponse(result, 'http', subdomain, customdomain, subdirectory, prodomain);
|
package/lib/request.js
CHANGED
|
@@ -10,36 +10,51 @@ const https = require('https');
|
|
|
10
10
|
const {Resolver} = require('dns').promises;
|
|
11
11
|
const resolver = new Resolver();
|
|
12
12
|
resolver.setServers(['1.1.1.1', '1.0.0.1']);
|
|
13
|
+
const semverMajor = require('semver/functions/major');
|
|
14
|
+
const nodeVersion = semverMajor(process.versions.node);
|
|
13
15
|
|
|
14
16
|
const staticLookup = () => async (hostname, _options, callback) => {
|
|
15
17
|
try {
|
|
16
18
|
const ips = await resolver.resolve(hostname);
|
|
17
19
|
|
|
18
20
|
if (ips.length === 0) {
|
|
19
|
-
return callback(new
|
|
21
|
+
return callback(new errors.InternalServerError({message: `Unable to resolve ${hostname}`}));
|
|
20
22
|
}
|
|
21
23
|
|
|
22
|
-
|
|
24
|
+
if (nodeVersion >= 20) {
|
|
25
|
+
// Node 20+ uses a different callback signature
|
|
26
|
+
callback(null, [{address: ips[0], family: 4}]);
|
|
27
|
+
} else {
|
|
28
|
+
// Node 18 and below use the old callback signature
|
|
29
|
+
callback(null, ips[0], 4);
|
|
30
|
+
}
|
|
23
31
|
} catch (err) {
|
|
24
32
|
return callback(err);
|
|
25
33
|
}
|
|
26
34
|
};
|
|
27
35
|
|
|
28
36
|
module.exports.domain = (url) => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
37
|
+
/**
|
|
38
|
+
* @type {import('got').Options}
|
|
39
|
+
*/
|
|
32
40
|
const options = {
|
|
33
41
|
// We want to capture details of different hops
|
|
34
42
|
followRedirect: false,
|
|
35
43
|
// Don't allow the request to go on for more than 15 seconds
|
|
36
|
-
timeout:
|
|
44
|
+
timeout: {
|
|
45
|
+
request: 15000
|
|
46
|
+
},
|
|
37
47
|
// If the network errors, retry 1 time:
|
|
38
|
-
|
|
48
|
+
retry: {
|
|
49
|
+
limit: 1
|
|
50
|
+
},
|
|
39
51
|
headers: {
|
|
40
52
|
'X-Ghost-Proxy': true
|
|
41
53
|
},
|
|
42
|
-
agent:
|
|
54
|
+
agent: {
|
|
55
|
+
http: new http.Agent({lookup: staticLookup()}),
|
|
56
|
+
https: new https.Agent({lookup: staticLookup()})
|
|
57
|
+
}
|
|
43
58
|
};
|
|
44
59
|
|
|
45
60
|
const responses = [];
|
|
@@ -51,11 +66,11 @@ module.exports.domain = (url) => {
|
|
|
51
66
|
const statusCode = res.statusCode;
|
|
52
67
|
const headers = {};
|
|
53
68
|
|
|
54
|
-
_.reduce(res.headers, (
|
|
69
|
+
_.reduce(res.headers, (updatedHeaders = {}, value, name) => {
|
|
55
70
|
if (_.startsWith(name, 'x-ghost') || _.includes(['server', 'location', 'x-amz-cf-id'], name)) {
|
|
56
|
-
|
|
71
|
+
updatedHeaders[name] = value;
|
|
57
72
|
}
|
|
58
|
-
return
|
|
73
|
+
return updatedHeaders;
|
|
59
74
|
}, headers);
|
|
60
75
|
|
|
61
76
|
responses.push({statusCode, headers});
|
|
@@ -78,9 +93,12 @@ module.exports.domain = (url) => {
|
|
|
78
93
|
.then(handleResponse)
|
|
79
94
|
.then(() => resolve(responses))
|
|
80
95
|
.catch((error) => {
|
|
81
|
-
reject(new errors.BadRequestError(
|
|
82
|
-
|
|
83
|
-
|
|
96
|
+
reject(new errors.BadRequestError({
|
|
97
|
+
message: 'Domain could not be requested',
|
|
98
|
+
property: url,
|
|
99
|
+
context: error.message,
|
|
100
|
+
code: error.code
|
|
101
|
+
}));
|
|
84
102
|
});
|
|
85
103
|
});
|
|
86
104
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/domain-validator",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "ssh://git@github.com/TryGhost/Pro",
|
|
@@ -25,18 +25,18 @@
|
|
|
25
25
|
"test": "NODE_ENV=testing mocha -- $(find test -name '*.test.js')"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"mocha": "
|
|
28
|
+
"mocha": "11.7.5",
|
|
29
29
|
"should": "13.2.3",
|
|
30
|
-
"sinon": "
|
|
30
|
+
"sinon": "21.0.3"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@tryghost/debug": "0.
|
|
34
|
-
"@tryghost/dns": "^0.
|
|
35
|
-
"@tryghost/errors": "
|
|
36
|
-
"@tryghost/pretty-cli": "
|
|
33
|
+
"@tryghost/debug": "2.0.3",
|
|
34
|
+
"@tryghost/dns": "^0.6.0",
|
|
35
|
+
"@tryghost/errors": "3.0.3",
|
|
36
|
+
"@tryghost/pretty-cli": "3.0.3",
|
|
37
37
|
"bluebird": "3.7.2",
|
|
38
|
-
"got": "8.
|
|
39
|
-
"lodash": "4.17.
|
|
38
|
+
"got": "11.8.6",
|
|
39
|
+
"lodash": "4.17.23"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "ef060c71be33d265e7d97e4579ed83c3e3fdac09"
|
|
42
42
|
}
|