-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
68 lines (60 loc) · 1.89 KB
/
server.js
File metadata and controls
68 lines (60 loc) · 1.89 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const http = require('http');
const domainRepo = require('./DomainRepository');
const dns = require('dns');
function getWebsiteSource(url) {
return new Promise((resolve, reject) => {
var options = {
host: url,
port: 80,
path: '/'
};
http.get(options, function (res) {
res.setEncoding("utf8");
let content = '';
res.on("data", function (chunk) {
content += chunk;
});
res.on("end", function () {
resolve(content);
});
}).on('error', function (e) {
reject(e.message);
});
})
}
// controllers
// function get('domain:/id', function(req, res) {})
function get(domain) {
domainRepo.getOne(domain).then(res => {
if (res.hasStats) {
console.log(res);
} else {
console.log('no data');
dns.resolve4(domain, (err, data) => {
if (err) {
res.isAlive = false;
} else {
console.log(err);
res.isAlive = true;
getWebsiteSource(domain).then(data => {
res.hasStats = true;
if (data.toLowerCase().indexOf('wordpress') > -1) {
res.stats = {
platform: 'wordpress'
}
} else {
res.stats = {
platform: 'other'
}
}
console.log(res);
domainRepo.update(domain, res).then(res => {
console.log('update success')
});
});
}
})
}
})
}
get('ckmisrael.co.il');