twilson63/cloudq3 — pull request #1 by akennedy (2013-04-22 17:36:55+00:00)
Title: fix issue where port in config file was getting overwritten

I was setting port in config.json like so:

{ "expire":259200,
"auth":{
"username":"foo",
"password":"bar" },
"namespace":"cloudq3",
"port":"3001",
"redis":{
"host":"localhost",
"port": 6379 }
}

And then run:

cloudq3 --legacy --config ~/config.json

And I would get EADDRINUSE (rails was running on 3000) because it was defaulting to 3000 even though I was setting port to 3001 in my config file.

So the changes I make here allow you to set the port in the config file. You can also override the port set in the config file with the --port flag. If port is not set in config.json nor is the --port flag set, then it will default to 3000

So, if I have a config.json of:

{ "expire":259200,
"auth":{
"username":"foo",
"password":"bar" },
"namespace":"cloudq3",
"port":"3001",
"redis":{
"host":"localhost",
"port": 6379 }
}

and run

cloudq3 --legacy --config ~/config.json

then it will listen on port `3001`

and if I run

cloudq3 --legacy --port 3002 --config ~/config.json

then it will run on port `3002`

and if my config file does not include port and I run

cloudq3 --legacy --config ~/config.json

then it will run on `3000`.

So basically the else block was always overriding my config file

if (commander.port) {
config.port = commander.port;
} else {
config.port = 3000;
}

But it will default to 3000 in the server.js here if none is set:

server.listen(config.port || 3000, function() {
console.log('~ Cloudq3 ~');
console.log('Listening on %s', config.port || 3000);
});