diff --git a/cloudcmd.js b/cloudcmd.js index 069d4b11..981ff505 100644 --- a/cloudcmd.js +++ b/cloudcmd.js @@ -23,7 +23,7 @@ REQUEST = 'request', RESPONSE = 'response', - INDEX = HTMLDIR + 'index.html', + INDEX = main.INDEX, CONFIG_PATH = JSONDIR + 'config.json', FS = CloudFunc.FS; @@ -197,8 +197,6 @@ if(!Config.minification) main.config = Config = lReadedConf; - console.log(Config); - Util.tryCatchLog(function(){ Config.minification.js = lReadedConf.minification.js; Config.cache = lReadedConf.cache; diff --git a/lib/server/commander.js b/lib/server/commander.js index 91ed0348..97072db3 100644 --- a/lib/server/commander.js +++ b/lib/server/commander.js @@ -25,7 +25,7 @@ OK = main.OK, FS = CloudFunc.FS, - INDEX = null, + INDEX, REQUEST = 'request', RESPONSE = 'response', @@ -33,16 +33,17 @@ exports.sendContent = function(pParams){ - var lRet = Util.checkObj(pParams, - ['processing'], - [REQUEST, RESPONSE, 'index']); + var lRet = Util.checkObjTrue(pParams, [REQUEST, RESPONSE, 'index']); if(lRet){ var p = pParams, lPath = getCleanPath(p.request); - INDEX = p.index; - IndexProcessingFunc = pParams.processing; + if(!INDEX) + INDEX = p.index; + + if(!IndexProcessingFunc) + IndexProcessingFunc = pParams.processing; fs.stat(lPath, function(pError, pStat){ if(!pError) @@ -233,7 +234,7 @@ * высылаем json-структуру файлов * с соответствующими заголовками */ - lList = JSON.stringify(lJSON); + lList = Util.stringifyJSON(lJSON); sendResponse({ name : lDirPath + '.json', diff --git a/lib/server/main.js b/lib/server/main.js index 2668c8d1..ebaef19d 100644 --- a/lib/server/main.js +++ b/lib/server/main.js @@ -4,7 +4,7 @@ /* Global var accessible from any loaded module */ global.cloudcmd = {}; - var DIR, LIBDIR, SRVDIR, JSONDIR, + var DIR, LIBDIR, SRVDIR, JSONDIR, HTMLDIR, Util, SLASH, @@ -23,7 +23,7 @@ /* Consts */ exports.OK = OK = 200; - exports.FILE_NOT_FOUND = 404; + exports.FILE_NOT_FOUND = FILE_NOT_FOUND = 404; exports.REQUEST = 'request'; exports.RESPONSE = 'response'; @@ -45,8 +45,9 @@ exports.SRVDIR = SRVDIR = __dirname + SLASH, exports.LIBDIR = LIBDIR = path.normalize(SRVDIR + '../'), exports.DIR = DIR = path.normalize(LIBDIR + '../'), - exports.HTMLDIR = DIR + 'html' + SLASH, + exports.HTMLDIR = HTMLDIR = DIR + 'html' + SLASH, exports.JSONDIR = JSONDIR = DIR + 'json' + SLASH, + exports.INDEX = HTMLDIR + 'index.html', /* Functions */ exports.require = mrequire, @@ -189,8 +190,6 @@ if(p.gzip) lRet['content-encoding'] = 'gzip'; - - Util.log(Config); } return lRet; diff --git a/lib/server/rest.js b/lib/server/rest.js index c24d5cf1..99f0a42e 100644 --- a/lib/server/rest.js +++ b/lib/server/rest.js @@ -87,8 +87,14 @@ lCmd = Util.removeStr(lCmd, '/'); pParams.command = lCmd; } - if(lCmd === 'fs') - onFS(pParams); + + if( Util.isContainStr(lCmd, 'fs') ){ + pParams.request.url += '?json'; + onFS({ + request : pParams.request, + response: pParams.response, + }); + } else switch(lMethod){ case 'GET': @@ -108,11 +114,15 @@ lMethod = pParams.method; switch(lMethod){ case 'GET': - pParams.data = { - mesage: 'fs called' - }; - send(pParams); - lResult = true; + var lINDEX = main.INDEX, + lName = main.minify.allowed.html ? + main.minify.getName(lINDEX) : lINDEX; + lResult = main.commander.sendContent({ + request : pParams.request, + response : pParams.response, + index : lName + }); + break; case 'PUT':