forked from qawemlilo/node-ping
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
39 lines (29 loc) · 812 Bytes
/
app.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
"use strict"
var Monitor = require('ping-monitor');
var websites = require('./websites');
var http = require('http');
var port = process.env.PORT || 3008;
var events = require('./events');
var urls = [];
var monitors = [];
/*
Loop over all websites and create a Monitor instance for each one.
*/
websites.forEach(function (website) {
var monitor = new Monitor ({
website: website.url,
interval: website.interval
});
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) {
res.end(urls.join('\n'));
}).listen(port);
console.log('Listening to port %s', port);