From a3b0d10d819c56cb95e25dd12c380e55e0655f6e Mon Sep 17 00:00:00 2001 From: coderaiser Date: Fri, 6 Jul 2012 07:55:15 -0400 Subject: [PATCH] added testing mode to server --- config.json | 3 ++- server.js | 67 +++++++++++++++++++++++++++++++++------------------- test/test.sh | 3 ++- 3 files changed, 47 insertions(+), 26 deletions(-) diff --git a/config.json b/config.json index e1e4ae3b..46b5b03f 100644 --- a/config.json +++ b/config.json @@ -5,5 +5,6 @@ "css" : true, "html" : true, "img" : true - } + }, + "server" : false } \ No newline at end of file diff --git a/server.js b/server.js index 0e676b66..12ba0684 100644 --- a/server.js +++ b/server.js @@ -4,6 +4,20 @@ * серверной части Cloud Commander'а */ var CloudServer={ + /* main Cloud Commander configuration + * readed from config.json if it's + * exist + */ + Config : { + "cache" : {"allowed" : true}, + "minification" : { + "js" : false, + "css" : false, + "html" : true, + "img" : false + }, + "server" : true + }, /* функция, которая генерирует заголовки * файлов, отправляемые сервером клиенту */ @@ -194,33 +208,28 @@ CloudServer.init=(function(){ console.log('server dir: ' + lServerDir); process.chdir(lServerDir); - var lConfig={ - "cache" : {"allowed" : true}, - "minification" : { - "js" : false, - "css" : false, - "html" : true, - "img" : false - } - }; try{ console.log('reading configureation file config.json...'); - lConfig=require('./config'); + CloudServer.Config = require('./config'); console.log('config.json readed'); + /* if command line parameter testing resolved + * setting config to testing + */ + if(process.argv[1]==='testing')CloudServer.Config.server=false; }catch(pError){ console.log('warning: configureation file config.json not found...\n' + 'using default values...\n' + - JSON.stringify(lConfig)); - } + JSON.stringify(CloudServer.Config)); + } /* Переменная в которой храниться кэш*/ - CloudServer.Cache.setAllowed(lConfig.cache.allowed); + CloudServer.Cache.setAllowed(CloudServer.Config.cache.allowed); /* Change default parameters of * js/css/html minification */ - CloudServer.Minify.setAllowed(lConfig.minification); + CloudServer.Minify.setAllowed(CloudServer.Config.minification); /* Если нужно минимизируем скрипты */ - CloudServer.Minify.doit(); + CloudServer.Minify.doit(); }); @@ -242,15 +251,25 @@ CloudServer.start=function() CloudServer.IP = process.env.IP || /* c9 */ CloudServer.IP; - var http = require('http'); - http.createServer(CloudServer._controller).listen( - CloudServer.Port, - CloudServer.IP); - - console.log('Cloud Commander server running at http://' + - CloudServer.IP + - ':' + - CloudServer.Port); + /* server mode or testing mode */ + if(CloudServer.Config.server){ + var http = require('http'); + try{ + http.createServer(CloudServer._controller).listen( + CloudServer.Port, + CloudServer.IP); + + console.log('Cloud Commander server running at http://' + + CloudServer.IP + + ':' + + CloudServer.Port); + }catch(pError){ + console.log('Cloud Commander server could not started'); + console.log(pError); + } + }else{ + console.log('Cloud Commander testing mode'); + } /* (!lC9Port? (!lCloudFoundryPort? diff --git a/test/test.sh b/test/test.sh index 107de656..fc87101f 100644 --- a/test/test.sh +++ b/test/test.sh @@ -5,4 +5,5 @@ jshint --config ./.jshintrc ./server.js ./client.js echo "jshint ./lib/cloudfunc.js ./lib/server/minify.js ./lib/client/keyBinding.js" jshint --config ./.jshintrc ./lib/cloudfunc.js ./lib/server/minify.js ./lib/client/keyBinding.js echo "jshint ./package.json ./config.json" -jshint --config ./.jshintrc ./package.json ./config.json \ No newline at end of file +jshint --config ./.jshintrc ./package.json ./config.json +node server.js testing \ No newline at end of file