Added exception handling and random port

This commit is contained in:
Brad Metcalf 2015-04-01 00:03:20 -05:00
commit 9d6fac6a67

View file

@ -7,6 +7,10 @@ var app = express();
var os = require('os'); var os = require('os');
var os = os.platform(); var os = os.platform();
process.on('uncaughtException', function(err){
changeState('<strong>'+err+'</strong>', '#CD0000');
});
win.title = gui.App.manifest.name; win.title = gui.App.manifest.name;
var bin = gui.App.manifest.phpwebkit.bin; var bin = gui.App.manifest.phpwebkit.bin;
@ -34,7 +38,7 @@ if(host === undefined || host == "") {
var port = gui.App.manifest.phpwebkit.port; var port = gui.App.manifest.phpwebkit.port;
if(port === undefined || port == "") { if(port === undefined || port == "") {
port = 9090; port = 0;
} }
var phpinfo = { var phpinfo = {
@ -47,23 +51,25 @@ var phpinfo = {
}; };
var server = http.createServer(app); var server = http.createServer(app);
app.use('/', php.cgi(phpinfo)); app.use('/', php.cgi(phpinfo));
server.listen(port, host);
var url = 'http://'+host+':'+port+'/'; server.listen(port, host, function(){
var url = 'http://'+host+':'+server.address().port+'/';
http.get(url, function(res) { http.get(url, function(res) {
if(res.statusCode == 200) { if(res.statusCode == 200) {
changeState('Starting application...', '#00CD00'); changeState('Starting application...', '#00CD00');
} else { } else {
changeState('Starting application with error code '+res.statusCode, '#FCD116'); changeState('Starting application with error code '+res.statusCode, '#FCD116');
} }
window.location = url; window.location = url;
}).on('error', function(e) { }).on('error', function(e) {
changeState('<strong>ERROR: '+e.message+'</strong>', '#CD0000'); changeState('<strong>ERROR: '+e.message+'</strong>', '#CD0000');
});
}); });
function changeState(msg, color){ function changeState(msg, color){
$('body').css('background-color', color); $('body').css('background-color', color);
$('#loading p').html(msg); $('#loading p').html(msg);
} }