Skip to content
This repository has been archived by the owner on Jun 27, 2019. It is now read-only.

Commit

Permalink
Custom configuration server
Browse files Browse the repository at this point in the history
It allows to pass a custom configuration file as an argument.

This patch also update documentation.

Signed-off-by: Bruno Bottazzini <bruno.bottazzini@intel.com>
  • Loading branch information
Bruno Bottazzini committed Sep 18, 2015
1 parent 7a47efa commit ff7f614
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,15 @@ Depending of the nodejs installation the command might be:

## Server configuration

The sever configuration file can be found on server/configuration.json
Default sever configuration file can be found in path ```server/configuration.json```.

The configuration file has the following attributes:
The server accepts a configuration file as a parameter, to do it just pass the path of the custom configuration file when running the server for example:

node server/app.js /tmp/my_custom_configuration.json

If no argument is provided it will get the default server configuration file.

#### Configuration attributes

server_port:
The port listened by the server. Default: 3000
Expand Down
9 changes: 8 additions & 1 deletion server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,14 @@

try {
var app = express();
var jConf = getConfigurationJson();
var jConf;
var args = process.argv.slice(2);
var server = process.argv.slice(1)[0];
if (args.length === 0 || server.indexOf("protractor")) {
jConf = getConfigurationJson();
} else {
jConf = getConfigurationJson(args[0]);
}

app.use(session({
genid: function(req) {
Expand Down
11 changes: 8 additions & 3 deletions server/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,19 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
module.exports = function () {
var jConf = null;
this.getConfigurationJson = function() {
this.getConfigurationJson = function(confPath) {
try {
//Verify if it is first run
if (!jConf) {
var fs = require('fs');
var path = require('path');
var server_folder = path.join(__dirname, '..', 'server');
var file = fs.readFileSync(server_folder + '/configuration.json', 'utf8');
var file;
if (!confPath) {
var server_folder = path.join(__dirname, '..', 'server');
file = fs.readFileSync(server_folder + '/configuration.json', 'utf8');
} else {
file = fs.readFileSync(confPath, 'utf8');
}
jConf = JSON.parse(file);
return jConf;
} else {
Expand Down

0 comments on commit ff7f614

Please sign in to comment.