minor changes

This commit is contained in:
coderaiser 2013-02-22 11:18:19 -05:00
parent d98cb73f69
commit 79f2f34a79
5 changed files with 63 additions and 21 deletions

View file

@ -8,6 +8,7 @@
SRVDIR = main.SRVDIR,
CLIENTDIR = LIBDIR + 'client',
HTMLDIR = main.HTMLDIR,
JSONDIR = main.JSONDIR,
path = main.path,
fs = main.fs,
@ -18,7 +19,7 @@
server = main.librequire('server'),
Minify = main.minify,
Config = main.config,
Config,
REQUEST = 'request',
RESPONSE = 'response',
@ -29,16 +30,8 @@
* Win32 should be backslashes */
DIR = main.DIR;
readConfig();
server.start(Config, {
appcache : appCacheProcessing,
minimize : minimize,
rest : rest,
route : route
});
readConfig(init);
if(update)
update.get();
/**
* additional processing of index file
@ -136,7 +129,16 @@
return Util.exec(main.rest, pConnectionData);
}
function readConfig(){
function init(){
server.start(Config, {
appcache : appCacheProcessing,
minimize : minimize,
rest : rest,
route : route
});
if(update)
update.get();
/* Determining server.js directory
* and chang current process directory
@ -176,6 +178,36 @@
}
}
function readConfig(pCallBack){
var lConfPath = JSONDIR + 'config.json',
lReaded;
fs.readFile(lConfPath, function(pError, pData){
if(!pError){
Util.log('config: readed');
var lStr = pData.toString();
Util.log( lStr );
main.config = Config = JSON.parse(lStr);
}
else
Util.log(pError);
Util.exec(pCallBack);
});
if(!Config)
fs.watch(lConfPath, function(){
if(!lReaded){
lReaded = true;
readConfig();
}
setTimeout(function() {
lReaded = false;
}, 10000);
});
}
/**
* routing of server queries
*/

View file

@ -2,7 +2,7 @@
"api_url" : "/api/v1",
"appcache" : false,
"minification" : {
"js" : false,
"js" : true,
"css" : true,
"html" : true,
"img" : true

View file

@ -50,7 +50,7 @@
FallBack_s += lName + ' ' + lCurrentName[lName] + '\n';
exports.watch(lCurrentName[lName]);
}
else exports.watch(pFileNames[i]);
}
else exports.watch(pFileNames);
@ -90,7 +90,7 @@
if(fs.exists)
fs.exists(pFileName, lWatch_f);
else lWatch_f();
NamesList_s += pFileName + '\n';
FileNames[pFileName] = true;
}

View file

@ -53,6 +53,8 @@
/* compitability with old versions of node */
exports.fs.exists = exports.fs.exists || exports.path.exists;
//exports.fs.watch = isWin32 ? fs.watch : linuxWatch;
/* Needed Modules */
exports.util = Util = require(LIBDIR + 'util'),
@ -60,7 +62,6 @@
exports.zlib = zlib = mrequire('zlib'),
/* Main Information */
exports.config = jsonrequire('config');
exports.modules = jsonrequire('modules');
exports.ext = ext = jsonrequire('ext');
exports.mainpackage = rootrequire('package');
@ -240,4 +241,12 @@
return lQuery;
}
function linuxWatch(pFile, pCallBack){
fs.watchFile(pFile, function(pCurr, pPrev){
if(pCurr.mtime !== pPrev.mtime)
Util.exec(pCallBack);
});
}
})();

View file

@ -1,7 +1,7 @@
/* RESTfull module */
(function(){
"use strict";
'use strict';
if(!global.cloudcmd)
return console.log(
@ -15,8 +15,7 @@
var main = global.cloudcmd.main,
Util = main.util,
Config = main.config,
APIURL = Config.api_url,
OK = 200,
Header = main.generateHeaders('api.json', false);
@ -29,13 +28,15 @@
lReq = pParams.request,
lRes = pParams.response,
lUrl = lReq.url,
lMethod = lReq.method;
lMethod = lReq.method,
lConfig = main.config,
lAPIURL = lConfig.api_url;
if( Util.isContainStr(lUrl, APIURL) ){
if( Util.isContainStr(lUrl, lAPIURL) ){
lRet = true;
getBody(lReq, function(pBody){
var lCommand = Util.removeStr(lUrl, APIURL),
var lCommand = Util.removeStr(lUrl, lAPIURL),
lData = getData({
command : lCommand,
method : lMethod,