diff --git a/cloudcmd.js b/cloudcmd.js index 6984efbc..85815a22 100644 --- a/cloudcmd.js +++ b/cloudcmd.js @@ -1,21 +1,59 @@ "use strict"; -var DIR = process.cwd() + '/', - SRVDIR = DIR + 'lib/server/', +var DIR = process.cwd() + '/', + LIBDIR = DIR + 'lib/', + SRVDIR = LIBDIR + 'server/', - srvfunc = require(SRVDIR + 'srvfunc'), - path = require('path'), - fs = require('fs'), - Server = srvfunc.require(DIR + 'server'), - update = srvfunc.require(SRVDIR + 'update'), + srvfunc = require(SRVDIR + 'srvfunc'), + path = require('path'), + fs = require('fs'), + Server = srvfunc.require(DIR + 'server'), + CloudFunc = srvfunc.require(LIBDIR +'cloudfunc'), + update = srvfunc.require(SRVDIR + 'update'), Config = readConfig(); -Server.start(Config); +Server.start(Config, indexProcessing); if(update) update.get(); +function indexProcessing(pIndex, pList){ + var lWin32 = process.platform === 'win32'; + + /* если выбрана опция минифизировать скрпиты + * меняем в index.html обычные css на + * минифицированый + */ + if(Server.CloudServer.Minify._allowed.css){ + var lReplace_s = ''; + else + lReplace_s = lReplace_s + '"/css/reset.css">'; + + pIndex = pIndex.replace(lReplace_s, ''); + pIndex = pIndex.replace('/css/style.css', Server.CloudServer.Minify.MinFolder + 'all.min.css'); + } + + pIndex = pIndex.replace('
', + '
'+ pList); + + /* меняем title */ + pIndex = pIndex.replace('Cloud Commander', + '' + CloudFunc.setTitle() + ''); + + if(!Server.CloudServer.Config.appcache){ + if(lWin32) + pIndex = pIndex.replace(' manifest=/cloudcmd.appcache', ''); + else + pIndex = pIndex.replace(' manifest="/cloudcmd.appcache"', ''); + } + + return pIndex; + +} + function readConfig(){ diff --git a/server.js b/server.js index dde2f928..d6d9becd 100644 --- a/server.js +++ b/server.js @@ -155,14 +155,16 @@ CloudServer.init = (function(){ * Функция создаёт сервер * @param pConfig */ -CloudServer.start = function (pConfig) { +CloudServer.start = function (pConfig, pIndexProcessing) { if(pConfig) this.Config = pConfig; else console.log('warning: configuretion file config.json not found...\n' + 'using default values...\n' + JSON.stringify(this.Config)); - + + CloudServer.indexProcessing = pIndexProcessing; + this.init(); this.Port = process.env.PORT || /* c9 */ @@ -675,37 +677,7 @@ CloudServer.indexReaded = function(pList){ pIndex = pIndex.toString(); - var lWin32 = process.platform === 'win32'; - - /* если выбрана опция минифизировать скрпиты - * меняем в index.html обычные css на - * минифицированый - */ - if(CloudServer.Minify._allowed.css){ - var lReplace_s = ''; - else - lReplace_s = lReplace_s + '"/css/reset.css">'; - - pIndex = pIndex.replace(lReplace_s, ''); - pIndex = pIndex.replace('/css/style.css', CloudServer.Minify.MinFolder + 'all.min.css'); - } - - pIndex = pIndex.toString().replace('
', - '
'+pList); - - /* меняем title */ - pIndex = pIndex.replace('Cloud Commander', - '' + CloudFunc.setTitle() + ''); - - if(!CloudServer.Config.appcache){ - if(lWin32) - pIndex = pIndex.replace(' manifest=/cloudcmd.appcache', ''); - else - pIndex = pIndex.replace(' manifest="/cloudcmd.appcache"', ''); - } - + pIndex = CloudServer.indexProcessing(pIndex, pList); /* * если браузер поддерживает gzip-сжатие * высылаем заголовок в зависимости от типа файла @@ -830,6 +802,7 @@ CloudServer.sendResponse = function(pHead, pData, pName){ } }; -exports.start = function(pConfig){ - CloudServer.start(pConfig); -}; \ No newline at end of file +exports.start = function(pConfig, pIndexProcessing){ + CloudServer.start(pConfig, pIndexProcessing); +}; +exports.CloudServer = CloudServer; \ No newline at end of file