refactored

This commit is contained in:
coderaiser 2012-11-15 06:49:53 -05:00
parent 9d626975d1
commit 9c98bd901f
5 changed files with 93 additions and 35 deletions

View file

@ -23,9 +23,14 @@
if(update)
update.get();
function indexProcessing(pIndex, pList){
var lReplace_s;
/**
* additional processing of index file
*
*/
function indexProcessing(pData){
var lReplace_s,
lData = pData.data,
lAdditional = pData.additional;
/* если выбрана опция минифизировать скрпиты
* меняем в index.html обычные css на
* минифицированый
@ -33,26 +38,26 @@
if(srv.Minify._allowed.css){
lReplace_s = '<link rel=stylesheet href="/css/reset.css">';
pIndex = Util.removeStr(pIndex, lReplace_s);
pIndex = pIndex.replace('/css/style.css', srv.Minify.MinFolder + 'all.min.css');
lData = Util.removeStr(lData, lReplace_s);
lData = lData.replace('/css/style.css', srv.Minify.MinFolder + 'all.min.css');
}
lReplace_s = '<div id=fm class=no-js>';
pIndex = pIndex.replace(lReplace_s, lReplace_s + pList);
lData = lData.replace(lReplace_s, lReplace_s + lAdditional);
/* меняем title */
pIndex = pIndex.replace('<title>Cloud Commander</title>',
lData = lData.replace('<title>Cloud Commander</title>',
'<title>' + CloudFunc.setTitle() + '</title>');
if(!srv.Config.appcache)
pIndex = Util.removeStr(pIndex, ' manifest=/cloudcmd.appcache');
lData = Util.removeStr(lData, ' manifest=/cloudcmd.appcache');
if(!srv.Config.show_keys_panel){
var lKeysPanel = '<div id=keyspanel';
pIndex = pIndex.replace(lKeysPanel, lKeysPanel +' class=hidden');
lData = lData.replace(lKeysPanel, lKeysPanel +' class=hidden');
}
return pIndex;
return lData;
}
@ -101,12 +106,12 @@
Config.server =
Config.logs = false;
}
if (Config.logs) {
console.log('log param setted up in config.json\n' +
'from now all logs will be writed to log.txt');
writeLogsToFile();
}
}
}
}

View file

@ -14,5 +14,6 @@
"logs" : false,
"socket" : true,
"port" : 80,
"ip" : "127.0.0.1"
"ip" : "127.0.0.1",
"rest" : true
}

View file

@ -35,13 +35,14 @@
/* Additional Modules */
exports.appcache = srvrequire('appcache'),
exports.cloudfunc = librequire('cloudfunc'),
exports.auth = srvrequire('auth'),
exports.appcache = srvrequire('appcache'),
exports.cache = srvrequire('cache').Cache,
exports.cloudfunc = librequire('cloudfunc'),
exports.rest = srvrequire('rest'),
exports.socket = srvrequire('socket'),
exports.update = srvrequire('update'),
exports.minify = srvrequire('minify').Minify,
exports.cache = srvrequire('cache').Cache,
exports.zlib = mrequire('zlib');

View file

@ -1,16 +1,63 @@
/* RESTfull module */
var APIURL;
exports.rest = function(req){
var lUrl = req.url,
lMethod = req.method;
/* if lUrl contains api url */
if( lUrl.indexOf(APIURL) === 0 ){
lUrl = lUrl.replace(APIURL, '');
(function(){
"use strict";
var DIR = process.cwd() + '/',
main = require(DIR + 'lib/server/main.js'),
SRVDIR = main.SRVDIR,
Util = main.util,
APIURL = '/api/v1/';
exports.rest = function(req, res, pCallBack){
var lUrl = req.url,
lMethod = req.method;
console.log(lUrl);
/* if lUrl contains api url */
if( Util.isContainStr(lUrl, APIURL) ){
lUrl = lUrl.replace(APIURL, '');
console.log(lUrl);
}
console.log(req.url);
console.log(lMethod);
Util.exec(pCallBack);
/*
switch(req.method){
case 'GET':
switch(lCommand){
case 'count':
lResult = {
count : Users.length,
};
break;
case 'list':
lResult = Users;
break;
}
break;
case 'PUT':
if( lCommand.indexOf('register') === 0 ){
lResult = {
registered : true,
name : req.body.name,
server_time : Util.getTime(),
client_time : req.body.time
};
Users.push(req.body.name);
console.log(lResult);
console.log(req.connection.remoteAddress);
}
break;
}
*/
console.log(req.url);
console.log(req.method);
}
}
};
})();

View file

@ -102,11 +102,11 @@ if(!Zlib)
'you should use newer node version\n');
/* добавляем модуль с функциями */
var CloudFunc = main.cloudfunc,
Util = main.util;
var CloudFunc = main.cloudfunc,
Util = main.util;
/* Обьект для работы с кэшем */
CloudServer.Cache = main.cache,
CloudServer.Cache = main.cache,
CloudServer.Minify = main.minify,
CloudServer.AppCache = main.appcache,
@ -665,9 +665,13 @@ CloudServer.indexReaded = function(pList){
pIndex = pIndex.toString();
var lProccessed = Util.exec(function(){
return CloudServer.indexProcessing(pIndex, pList);
});
var lProccessed,
lIndexProccessing = CloudServer.indexProcessing;
lProccessed = Util.exec(lIndexProccessing, {
data : pIndex,
additional : pList
});
if(lProccessed)
pIndex = lProccessed;