From 57101a19c435f3b7f34d5ef9a67ac86a46615ced Mon Sep 17 00:00:00 2001 From: coderaiser Date: Wed, 31 Oct 2012 11:46:53 -0400 Subject: [PATCH] refactored with util module --- lib/util.js | 2 +- server.js | 34 ++++++++++++++++++++++------------ 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/lib/util.js b/lib/util.js index b1cf889f..eeea3fca 100644 --- a/lib/util.js +++ b/lib/util.js @@ -112,4 +112,4 @@ var Util, exports; return lRet; }; -}()); \ No newline at end of file +})(); \ No newline at end of file diff --git a/server.js b/server.js index 455f2c2c..a98e531f 100644 --- a/server.js +++ b/server.js @@ -111,7 +111,9 @@ if(!Zlib) 'you should use newer node version\n'); /* добавляем модуль с функциями */ -var CloudFunc = srvfunc.require(LIBDIR + 'cloudfunc'); +var CloudFunc = srvfunc.require(LIBDIR + 'cloudfunc'), + Util = srvfunc.require(LIBDIR + 'util'); + CloudServer.AppCache = srvfunc.require(SRVDIR + 'appcache'); CloudServer.Socket = srvfunc.require(SRVDIR + 'socket'); @@ -223,19 +225,21 @@ CloudServer.generateHeaders = function(pName, pGzip){ lContentEncoding = '', lDot = pName.lastIndexOf('.'), - lExt = pName.substr(lDot); + lExt = pName.substr(lDot); - if(lExt === '.appcache') + if( Util.strCmp(lExt, '.appcache') ) lCacheControl = 1; lType = CloudServer.Extensions[lExt] || 'text/plain'; - if(lType.indexOf('img') < 0) + + if( !Util.isContainStr(lType, 'img') ) lContentEncoding = '; charset=UTF-8'; var lQuery = CloudServer.Queries[pName]; if(lQuery){ - if(lQuery === 'download') + if( Util.strCmp(lQuery, 'download') ) lType = 'application/octet-stream'; + console.log(pName + lQuery); } @@ -249,7 +253,7 @@ CloudServer.generateHeaders = function(pName, pGzip){ 'Content-Type': lType + lContentEncoding, 'cache-control': 'max-age=' + lCacheControl, 'last-modified': new Date().toString(), - 'content-encoding': pGzip?'gzip':'', + 'content-encoding': pGzip? 'gzip' : '', /* https://developers.google.com/speed/docs/best-practices /caching?hl=ru#LeverageProxyCaching */ 'Vary': 'Accept-Encoding' @@ -311,10 +315,13 @@ CloudServer._controller = function(pReq, pRes) * ни о том, что это корневой * каталог - загружаем файлы проэкта */ - if(pathname.indexOf(lFS_s) < 0 && - pathname.indexOf(lNoJS_s) < 0 && - pathname!=='/' && - lQuery !=='json'){ + + + + if ( !Util.isContainStr(pathname, lFS_s) && + !Util.isContainStr(pathname, lNoJS_s) && + !Util.strCmp(pathname, '/') && + !Util.strCmp(lQuery, 'json') ) { /* если имена файлов проекта - загружаем их*/ /* убираем слеш и читаем файл с текущец директории*/ @@ -678,8 +685,11 @@ CloudServer.indexReaded = function(pList){ pIndex = pIndex.toString(); - if(typeof CloudServer.indexProcessing === 'function') - pIndex = CloudServer.indexProcessing(pIndex, pList); + var lProccessed = Util.exec(function(){ + return CloudServer.indexProcessing(pIndex, pList); + }); + if(lProccessed) + pIndex = lProccessed; /* * если браузер поддерживает gzip-сжатие * высылаем заголовок в зависимости от типа файла