mino changes

This commit is contained in:
coderaiser 2013-02-23 03:49:26 -05:00
parent 8eac958e86
commit ceb21afd39
3 changed files with 38 additions and 36 deletions

View file

@ -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);
});
}
/**

View file

@ -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;
})();

View file

@ -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
},
/*