From 9d6fac6a671e9c2232d12ce8f965091cd4d62c15 Mon Sep 17 00:00:00 2001 From: Brad Metcalf Date: Wed, 1 Apr 2015 00:03:20 -0500 Subject: [PATCH] Added exception handling and random port --- php-webkit/main.js | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/php-webkit/main.js b/php-webkit/main.js index eefe193..ee5b7b2 100644 --- a/php-webkit/main.js +++ b/php-webkit/main.js @@ -7,6 +7,10 @@ var app = express(); var os = require('os'); var os = os.platform(); +process.on('uncaughtException', function(err){ + changeState(''+err+'', '#CD0000'); +}); + win.title = gui.App.manifest.name; var bin = gui.App.manifest.phpwebkit.bin; @@ -34,7 +38,7 @@ if(host === undefined || host == "") { var port = gui.App.manifest.phpwebkit.port; if(port === undefined || port == "") { - port = 9090; + port = 0; } var phpinfo = { @@ -47,23 +51,25 @@ var phpinfo = { }; var server = http.createServer(app); + 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) { - if(res.statusCode == 200) { - changeState('Starting application...', '#00CD00'); - } else { - changeState('Starting application with error code '+res.statusCode, '#FCD116'); - } - window.location = url; -}).on('error', function(e) { - changeState('ERROR: '+e.message+'', '#CD0000'); + http.get(url, function(res) { + if(res.statusCode == 200) { + changeState('Starting application...', '#00CD00'); + } else { + changeState('Starting application with error code '+res.statusCode, '#FCD116'); + } + window.location = url; + }).on('error', function(e) { + changeState('ERROR: '+e.message+'', '#CD0000'); + }); }); function changeState(msg, color){ $('body').css('background-color', color); $('#loading p').html(msg); -} \ No newline at end of file +}