From ceb21afd39ec451ef30b1c4be7bb7c4c7bfbdf50 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Sat, 23 Feb 2013 03:49:26 -0500 Subject: [PATCH] mino changes --- cloudcmd.js | 28 +++++++++++++++------------- lib/server.js | 40 +++++++++++++++++----------------------- lib/server/main.js | 6 ++++++ 3 files changed, 38 insertions(+), 36 deletions(-) diff --git a/cloudcmd.js b/cloudcmd.js index 7f74ef3e..dd4f3f5e 100644 --- a/cloudcmd.js +++ b/cloudcmd.js @@ -24,6 +24,7 @@ REQUEST = 'request', RESPONSE = 'response', INDEX = HTMLDIR + 'index.html', + CONFIG_PATH = JSONDIR + 'config.json', FS = CloudFunc.FS; /* reinit main dir os if we on @@ -130,7 +131,14 @@ } function init(){ - server.start(Config, { + fs.watch(CONFIG_PATH, function(){ + /* every catch up - calling twice */ + setTimeout(function() { + readConfig(); + }, 1000); + }); + + server.start({ appcache : appCacheProcessing, minimize : minimize, rest : rest, @@ -179,28 +187,22 @@ } function readConfig(pCallBack){ - var lConfPath = JSONDIR + 'config.json'; - - fs.readFile(lConfPath, function(pError, pData){ + fs.readFile(CONFIG_PATH, function(pError, pData){ if(!pError){ Util.log('config: readed'); + var lStr = pData.toString(); - Util.log( lStr ); main.config = Config = JSON.parse(lStr); + + Util.tryCatchLog(function(){ + Minify.setAllowed(main.config.minify); + }); } else Util.log(pError); Util.exec(pCallBack); }); - - if(!Config) - fs.watch(lConfPath, function(){ - /* every catch up - calling twice */ - setTimeout(function() { - readConfig(); - }, 1000); - }); } /** diff --git a/lib/server.js b/lib/server.js index 078c945a..1e777cd9 100644 --- a/lib/server.js +++ b/lib/server.js @@ -1,5 +1,5 @@ (function(){ - "use strict"; + 'use strict'; if(!global.cloudcmd) return console.log( @@ -11,13 +11,6 @@ var main = global.cloudcmd.main, - /* base configuration */ - Config = { - server : true, - socket : true, - port : 80 - }, - DIR = main.Dir, LIBDIR = main.LIBDIR, SRVDIR = main.SRVDIR, @@ -37,7 +30,8 @@ /* базовая инициализация */ function init(pAppCachProcessing){ - var lMinifyAllowed = Config.minification; + var lConfig = main.config, + lMinifyAllowed = lConfig.minification; /* Change default parameters of * js/css/html minification @@ -48,7 +42,7 @@ Util.exec(Minimize, lMinifyAllowed); /* создаём файл app cache */ - if( Config.appcache && AppCache && Config.server ) + if( lConfig.appcache && AppCache && lConfig.server ) Util.exec( pAppCachProcessing ); } @@ -58,17 +52,16 @@ * @param pConfig * @param pProcessing {index, appcache, rest} */ - function start(pConfig, pProcessing) { + function start(pProcessing) { + var lConfig = main.config; + if(!pProcessing) pProcessing = {}; - - if(pConfig) - Config = pConfig; - + else Util.log('warning: configuretion file config.json not found...\n' + 'using default values...\n' + - JSON.stringify(Config)); + JSON.stringify(lConfig)); Rest = pProcessing.rest; Route = pProcessing.route; @@ -79,20 +72,20 @@ Port = process.env.PORT || /* c9 */ process.env.app_port || /* nodester */ process.env.VCAP_APP_PORT || /* cloudfoundry */ - Config.port; + lConfig.port; IP = process.env.IP || /* c9 */ - Config.ip || + lConfig.ip || (main.WIN32 ? '127.0.0.1' : '0.0.0.0'); /* server mode or testing mode */ - if (Config.server) { + if (lConfig.server) { var lError = Util.tryCatchLog(function(){ Server = http.createServer( controller ); Server.listen(Port, IP); var lListen; - if(Config.socket && Socket) + if(lConfig.socket && Socket) lListen = Socket.listen(Server); Util.log('* Sockets ' + (lListen ? 'running' : 'disabled')); @@ -118,6 +111,7 @@ { /* Читаем содержимое папки, переданное в url */ var lRet, + lConfig = main.config, lURL = main.url, lParsedUrl = lURL.parse(pReq.url), lPath = lParsedUrl.pathname; @@ -128,7 +122,7 @@ Util.log("request for " + lPath + " received..."); - if( Config.rest ) + if( lConfig.rest ) lRet = Util.exec(Rest, { request : pReq, response : pRes @@ -147,11 +141,12 @@ Util.log('reading ' + lName); /* watching is file changed */ - if(Config.appcache) + if(lConfig.appcache) AppCache.watch(lName); Util.log(Path.basename(lName)); + console.log(Minify.allowed); var lMin = Minify.allowed, lExt = Util.getExtension(lName), lResult = lExt === '.js' && lMin.js || @@ -178,7 +173,6 @@ } } - exports.start = start; })(); diff --git a/lib/server/main.js b/lib/server/main.js index 1a80fb20..b4f2ed3d 100644 --- a/lib/server/main.js +++ b/lib/server/main.js @@ -65,6 +65,12 @@ exports.modules = jsonrequire('modules'); exports.ext = ext = jsonrequire('ext'); exports.mainpackage = rootrequire('package'); + /* base configuration */ + exports.config = { + server : true, + socket : true, + port : 80 + }, /*