|
|
@@ -0,0 +1,67 @@
|
|
|
+#!/usr/bin/env node
|
|
|
+
|
|
|
+'use strict';
|
|
|
+
|
|
|
+require('colors');
|
|
|
+
|
|
|
+var superagent = require('superagent'),
|
|
|
+ http = require('http'),
|
|
|
+ fs = require('fs');
|
|
|
+
|
|
|
+var google = {
|
|
|
+ server: 'https://google.com',
|
|
|
+ tests: 0,
|
|
|
+ failCount: 0,
|
|
|
+ successCount: 0
|
|
|
+};
|
|
|
+
|
|
|
+var router = {
|
|
|
+ server: 'http://192.168.10.1',
|
|
|
+ tests: 0,
|
|
|
+ failCount: 0,
|
|
|
+ successCount: 0
|
|
|
+};
|
|
|
+
|
|
|
+function test(item) {
|
|
|
+ ++item.tests;
|
|
|
+
|
|
|
+ superagent.get(item.server, function (error, result) {
|
|
|
+ if (error) {
|
|
|
+ ++item.failCount;
|
|
|
+ console.log('Error: ', item.server, error.message);
|
|
|
+ // process.stdout.write('×'.red);
|
|
|
+ } else {
|
|
|
+ ++item.successCount;
|
|
|
+ // process.stdout.write('✓'.green);
|
|
|
+ }
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+setInterval(test.bind(null, google), 500);
|
|
|
+setInterval(test.bind(null, router), 500);
|
|
|
+
|
|
|
+function status(req, res) {
|
|
|
+ var body = {
|
|
|
+ google: google,
|
|
|
+ router: router
|
|
|
+ };
|
|
|
+
|
|
|
+ res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
|
+ res.end(JSON.stringify(body));
|
|
|
+}
|
|
|
+
|
|
|
+function sendSuperagent(req, res) {
|
|
|
+ res.writeHead(200, { 'Content-Type': 'application/javascript' });
|
|
|
+ res.end(fs.readFileSync('node_modules/superagent/superagent.js'));
|
|
|
+}
|
|
|
+
|
|
|
+http.createServer(function (req, res) {
|
|
|
+ if (req.url === '/status') return status(req, res);
|
|
|
+ if (req.url === '/superagent.js') return sendSuperagent(req, res);
|
|
|
+
|
|
|
+ res.writeHead(200, { 'Content-Type': 'text/html' });
|
|
|
+ res.end(fs.readFileSync('index.html'));
|
|
|
+}).listen(8000);
|
|
|
+
|
|
|
+console.log('Status page available on http://localhost:8000');
|
|
|
+
|