(function(){ 'use strict'; var DIR = __dirname + '/', main = require(DIR + 'lib/server/main'), LIBDIR = main.LIBDIR, SRVDIR = main.SRVDIR, CLIENTDIR = LIBDIR + 'client', HTMLDIR = main.HTMLDIR, JSONDIR = main.JSONDIR, path = main.path, fs = main.fs, CloudFunc = main.cloudfunc, AppCache = main.appcache, Util = main.util, update = main.update, server = main.librequire('server'), Minify = main.minify, Config = main.config, REQUEST = 'request', RESPONSE = 'response', INDEX = HTMLDIR + 'index.html', CONFIG_PATH = JSONDIR + 'config.json', FS = CloudFunc.FS; /* reinit main dir os if we on * Win32 should be backslashes */ DIR = main.DIR; readConfig(init); /** * additional processing of index file */ function indexProcessing(pData){ var lReplace_s, lData = pData.data, lAdditional = pData.additional; /* * если выбрана опция минимизировать скрипты * меняем в index.html обычные css на * минифицированый */ if(Minify.allowed.css){ var lPath = '/' + Minify.MinFolder.replace(DIR, ''); lReplace_s = ''; lData = Util.removeStr(lData, lReplace_s) .replace('/css/style.css', lPath + 'all.min.css'); } /* меняем title */ lReplace_s = '
'; lData = lData.replace(lReplace_s, lReplace_s + lAdditional) .replace('Cloud Commander', '' + CloudFunc.getTitle() + ''); if(!Config.appcache) lData = Util.removeStr(lData, ' manifest="/cloudcmd.appcache"'); if(!Config.show_keys_panel){ var lKeysPanel = '
' + p.name); pParams.name = main.HTMLDIR + p.name + '.html'; lRet = main.sendFile( pParams ); } else if( Util.isContainStr(p.name, FS) || Util.strCmp( p.name, '/') ){ if( Util.isContainStr(p.name, 'no-js/') ) return noJSTMPRedirection(pParams); var lQuery = main.getQuery(p.request), lName = Minify.allowed.html ? Minify.getName(INDEX) : INDEX; if( !lQuery ) p.request.url += '?html'; lRet = main.commander.sendContent({ request : p.request, response : p.response, processing : indexProcessing, index : lName }); } /* termporary redirect for old urls */ else lRet = false; } return lRet; } function noJSTMPRedirection(pParams){ var MOVED_PERMANENTLY = 301, lPath = Util.removeStr(pParams.name, 'no-js/'); pParams.response.writeHead(MOVED_PERMANENTLY, {'Location': lPath}); pParams.response.end(); return true; } /* function sets stdout to file log.txt */ function writeLogsToFile(){ var stdo = fs.createWriteStream('./log.txt'); process.stdout.write = (function(write) { return function(string, encoding, fd) { stdo.write(string); }; })(process.stdout.write); } })();