Revert "Restructuring and refactoring"

This reverts commit 766278abf9e1e96cf173a50665e2a7bde7d24460.
This commit is contained in:
Brad Metcalf 2015-04-02 23:55:06 -05:00
commit b49c49acf2

View file

@ -1,15 +1,15 @@
var phpwebkit = {
runApp: function(){
var gui = require('nw.gui'); var gui = require('nw.gui');
var win = gui.Window.get(); var win = gui.Window.get();
var http = require('http');
var fs = require('fs');
var php = require('../lib/bridge');
var express = require('express');
var app = express();
var os = require('os'); var os = require('os');
var os = os.platform(); var os = os.platform();
var pw = this;
process.on('uncaughtException', function(err){ process.on('uncaughtException', function(err){
pw.changeState('<strong>'+err+'</strong>', '#CD0000'); changeState('<strong>'+err+'</strong>', '#CD0000');
}); });
win.title = gui.App.manifest.name; win.title = gui.App.manifest.name;
@ -27,10 +27,8 @@ var phpwebkit = {
} }
} }
this.fileExists(bin, function(result){ binExists(bin, function(filename){
if(result === false) { bin = filename;
return 'php-cgi';
}
}); });
var path = gui.App.manifest.phpwebkit.path; var path = gui.App.manifest.phpwebkit.path;
@ -48,58 +46,38 @@ var phpwebkit = {
port = 0; port = 0;
} }
var config = { var phpinfo = {
"path": path, "path": path,
"bin": bin, "bin": bin,
"host": host, "host": host,
"port": port, "port": port,
"arguments": gui.App.argv, "arguments": gui.App.argv,
"manifest": gui.App.manifest "manifest": gui.App.manifest
} };
this.startServer(config);
},
startServer: function(config, callback){
var http = require('http');
var php = require('../lib/bridge');
var express = require('express');
var app = express();
var host = config.host;
var port = config.port;
var pw = this;
var server = http.createServer(app); var server = http.createServer(app);
app.use('/', php.cgi(config)); app.use('/', php.cgi(phpinfo));
server.listen(port, host, function(){ server.listen(port, host, function(){
pw.changeState('Starting application...', '#00CD00'); var url = 'http://'+host+':'+server.address().port+'/';
window.location = 'http://'+host+':'+server.address().port +'/'; changeState('Starting application...', '#00CD00');
}).on('error', function(err) { window.location = url;
pw.changeState('<strong>Error: '+server.err+'</strong>', '#CD0000'); }).on('error', function(e) {
changeState('<strong>Error: '+e.message+'</strong>', '#CD0000');
}); });
},
changeState: function(msg, color){
function changeState(msg, color){
$('body').css('background-color', color); $('body').css('background-color', color);
$('#loading p').html(msg); $('#loading p').html(msg);
}, }
fileExists: function(file, callback){ function binExists(file, callback){
fs.stat(bin, function(err, stats) {
var fs = require('fs');
fs.stat(file, function(err, stats) {
if(!err && stats.isFile()) { if(!err && stats.isFile()) {
return true; return stats.filename;
} else { } else {
return false; return 'php-cgi';
} }
}); });
} }
};
phpwebkit.runApp();