forked from qawemlilo/node-ping
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
43 lines (30 loc) · 853 Bytes
/
app.js
File metadata and controls
43 lines (30 loc) · 853 Bytes
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
var Monitor = require('ping-monitor'),
websites = require('./websites'),
http = require('http'),
port = process.env.PORT || 3008,
events = require('./events'),
urls = [],
monitors = [];
/*
Loop over all websites and create a Monitor instance for each one.
*/
websites.forEach(function (website) {
"use strict";
var monitor = new Monitor ({
website: website.url,
timeout: website.timeout
});
monitor.on('error', events.onError);
monitor.on('stop', events.onStop);
monitor.on('down', events.onDown);
urls.push(website.url);
monitors.push(monitor);
});
/*
Server for responding to http requests
*/
http.createServer(function (req, res) {
"use strict";
res.end(urls.join('\n'));
}).listen(port);
console.log('Listening to port %s', port);