boerhaave-arch
Version:
boerhaave architecture shell
62 lines (50 loc) • 1.6 kB
JavaScript
var http = require('http');
var fs = require('fs');
var url = require('url');
http.createServer( function (request, response) {
var pathname = url.parse(request.url).pathname;
console.log("Request for " + pathname + " received.");
fs.readFile(pathname.substr(1), function (err, data) {
if (err) {
console.log(err);
// HTTP Status: 404 : NOT FOUND
response.writeHead(404, {'Content-Type': 'text/html'});
}else {
// HTTP Status: 200 : OK
response.writeHead(200, {'Content-Type': 'text/html'});
response.write(data.toString());
}
response.end();
});
}).listen(8081,initApp);
console.log('Server running at http://127.0.0.1:8081/');
function initApp(){
//detect OS
var os = require('os');
var platform = os.platform();
console.log('OS platform is '+platform);
//Test Connection
require('dns').lookup('google.com',function(err) {
if (err && err.code == "ENOTFOUND") {
console.log('offline...');
} else {
console.log('online!');
}
})
//Prepare to Launch Chrome
var childProcess = require("child_process");
console.log('Attempting Browser Launch');
/*
Ubuntu
*/
if (platform === 'linux') {
childProcess.exec("google-chrome --kiosk http://127.0.0.1:8081/app/index.html");
};
/*
Windows
*/
if (platform === 'win32') {
//childProcess.exec("start chrome --kiosk http://127.0.0.1:8081/app/index.html");
childProcess.exec("start chrome --kiosk http://studiolouter.nl");
};
}