minor changes

This commit is contained in:
coderaiser 2013-02-05 06:55:20 -05:00
parent 067ad1fe10
commit 7673b7d32d
3 changed files with 47 additions and 61 deletions

View file

@ -188,17 +188,13 @@
'-> auth');
pParams.name = main.HTMLDIR + lName + '.html';
main.sendFile(pParams);
lRet = true;
lRet = main.sendFile(pParams);
}else if( Util.strCmp(lName, '/auth/github') ){
Util.log('* Routing' +
'-> github');
pParams.name = main.HTMLDIR + lName + '.html';
main.sendFile(pParams);
lRet = true;
lRet = main.sendFile(pParams);
}else if( Util.isContainStr(lName, CloudFunc.FS) ||
Util.isContainStr(lName, CloudFunc.NO_JS ) ||
Util.strCmp(lName, '/') ||

View file

@ -108,7 +108,7 @@
if (lConfig.server) {
var http = main.http,
lError = Util.tryCatchLog(Util.bind(function(){
this.Server = http.createServer(this._controller);
this.Server = http.createServer( controller );
this.Server.listen(this.Port, this.IP);
var lListen;
@ -134,10 +134,11 @@
* @param req - запрос клиента (Request)
* @param res - ответ сервера (Response)
*/
CloudServer._controller = function(pReq, pRes)
function controller(pReq, pRes)
{
/* Читаем содержимое папки, переданное в url */
var lConfig = CloudServer.Config,
var lRet,
lConfig = CloudServer.Config,
lURL = main.url,
lParsedUrl = lURL.parse(pReq.url),
lPath = lParsedUrl.pathname;
@ -146,69 +147,56 @@
lPath = Querystring.unescape(lPath);
Util.log('pathname: ' + lPath);
/* запоминаем поддерживает ли браузер
* gzip-сжатие при каждом обращении к серверу
* и доступен ли нам модуль zlib
*/
Util.log("request for " + lPath + " received...");
if( lConfig.rest ){
var lRestWas = Util.exec(CloudServer.rest, {
if( lConfig.rest )
lRet = Util.exec(CloudServer.rest, {
request : pReq,
response : pRes
});
if(lRestWas)
return;
}
if( CloudServer.route){
var lRouteWas = Util.exec(CloudServer.route, {
if( !lRet && CloudServer.route)
lRet = Util.exec(CloudServer.route, {
name : lPath,
request : pReq,
response : pRes
});
if(!lRet){
/* добавляем текующий каталог к пути */
var lName = '.' + lPath;
Util.log('reading ' + lName);
if(lRouteWas)
return;
/* watching is file changed */
if(lConfig.appcache)
AppCache.watch(lName);
Util.log(Path.basename(lName));
var lMin = Minify.allowed,
lExt = Util.getExtension(lName),
lResult = lExt === '.js' && lMin.js ||
lExt === '.css' && lMin.css ||
lExt === '.html' && lMin.html;
Util.ifExec(!lResult,
function(pParams){
var lSendName = pParams && pParams.name || lName;
main.sendFile({
name : lSendName,
request : pReq,
response : pRes
});
}, function(pCallBack){
Minify.optimize(lName, {
request : pReq,
response : pRes,
callback : pCallBack
});
});
}
/* если имена файлов проекта - загружаем их *
* убираем слеш и читаем файл с текущец директории */
/* добавляем текующий каталог к пути */
var lName = '.' + lPath;
Util.log('reading ' + lName);
/* watching is file changed */
if(lConfig.appcache)
AppCache.watch(lName);
Util.log(Path.basename(lName));
var lMin = Minify.allowed,
lExt = Util.getExtension(lName),
lResult = lExt === '.js' && lMin.js ||
lExt === '.css' && lMin.css ||
lExt === '.html' && lMin.html;
Util.ifExec(!lResult, function(pParams){
var lSendName = pParams && pParams.name || lName;
main.sendFile({
name : lSendName,
request : pReq,
response : pRes
});
}, function(pCallBack){
Minify.optimize(lName, {
request : pReq,
response : pRes,
callback : pCallBack
});
});
};
}
/**
* start server function

View file

@ -205,6 +205,8 @@
lReadStream = lReadStream.pipe( zlib.createGzip() );
lReadStream.pipe(lRes);
lRet = true;
}
return lRet;