diff --git a/cloudcmd.js b/cloudcmd.js index a318dbe4..fe9c3e3f 100644 --- a/cloudcmd.js +++ b/cloudcmd.js @@ -201,6 +201,7 @@ var ret, name, params, isAuth, isFS; if (request && response) { + ret = true; name = main.getPathName(request); isAuth = Util.strCmp(name, ['/auth', '/auth/github']); isFS = Util.strCmp(name, '/') || Util.isContainStrAtBegin(name, FS); diff --git a/lib/server.js b/lib/server.js index 3286edee..461cb180 100644 --- a/lib/server.js +++ b/lib/server.js @@ -104,7 +104,7 @@ controller ]); - Server = http.createServer(expressApp || controller); + Server = http.createServer(expressApp || respond); Server.on('error', Util.log.bind(Util)); Server.listen(lPort, lIP); @@ -137,7 +137,7 @@ redirectServer.listen(lPort, lIP); - Server = https.createServer(lSSL, controller); + Server = https.createServer(lSSL, respond); Server.on('error', function (error) { Util.log('Could not use https port: ' + lSSLPort); Util.log(error); @@ -156,6 +156,24 @@ Util.log('Cloud Commander testing mode'); } + function respond(req, res) { + var i, n, func, + funcs = ([ + Rest, + Route, + join, + controller + ]); + + n = funcs.length; + for (i = 0; i < n; i++) { + func = funcs[i]; + funcs[i] = func.bind(null, req, res); + } + + Util.loadOnLoad(funcs); + } + /** * Главная функция, через которую проихсодит @@ -165,14 +183,15 @@ */ function controller(pReq, pRes) { /* Читаем содержимое папки, переданное в url */ - var lRet, lName, lMin, lCheck, lResult, data, + var lRet, lMin, lCheck, lResult, data, lConfig = main.config, - lParsedUrl = URL.parse(pReq.url), - lQuery = lParsedUrl.search || '', - path = main.getPathName(pReq); + parsedUrl = URL.parse(pReq.url), + query = parsedUrl.search || '', + path = main.getPathName(pReq), + lName = path; if (!expressApp) - Util.log(pReq.method + ' ' + path + lQuery); + Util.log(pReq.method + ' ' + path + query); data = { name : path, @@ -180,45 +199,32 @@ response : pRes }; - if (lConfig.rest && !expressApp) - lRet = Util.exec(Rest, pReq, pRes); + /* watching is file changed */ + if (lConfig.appcache) + AppCache.watch(lName); - if (!lRet && !expressApp) - lRet = Util.exec(Route, pReq, pRes); + lName = Path.join(DIR, lName); + lMin = lConfig.minify, + lCheck = checkExtension(lName); + lResult = lMin && lCheck; - if (!lRet && !expressApp) - lRet = join(pReq, pRes); - - if (!lRet) { - lName = data.name; - - /* watching is file changed */ - if (lConfig.appcache) - AppCache.watch(lName); - - lName = Path.join(DIR, lName); - lMin = lConfig.minify, - lCheck = checkExtension(lName); - lResult = lMin && lCheck; - - Util.ifExec(!lResult, - function(pParams) { - var lSendName = pParams && pParams.name || lName; - - main.sendFile({ - name : lSendName, - cache : lConfig.cache, - gzip : true, - request : pReq, - response : pRes - }); - }, function(pCallBack) { - Minify.optimize(lName, { - callback : pCallBack, - returnName : true + Util.ifExec(!lResult, + function(pParams) { + var lSendName = pParams && pParams.name || lName; + + main.sendFile({ + name : lSendName, + cache : lConfig.cache, + gzip : true, + request : pReq, + response : pRes }); + }, function(pCallBack) { + Minify.optimize(lName, { + callback : pCallBack, + returnName : true }); - } + }); } function minify(name) {