-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheckwp.js
43 lines (36 loc) · 915 Bytes
/
checkwp.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const request = require('superagent');
let Promise = this.Promise || require('promise');
let agent = require('superagent-promise')(request, Promise);
let adminPath = "/wp-admin";
module.exports = checkUrl;
function checkUrl(domain) {
return new Promise(function (resolve, reject) {
if (!validDomain(domain)) {
resolve(false);
}
let responded = function(res) {
if (res !== null && res.status === undefined) {
resolve(false);
}
resolve(!res.notFound);
};
let failed = function (err) {
resolve(false);
};
return (agent
.get(domain + adminPath)
.end()
.then(responded)
.catch(failed)
);
});
}
function validDomain(domain) {
let array = ["twitter.com", "github.com", "i.redd.it", "i.imgur.com", "imgur.com", "gfycat.com", "youtu.be", "gamasutra.com"];
for (let i = 0; i < array.length ;i++) {
if (domain === array[i]) {
return false;
}
}
return true;
}