diff --git a/README.md b/README.md index 5cbe4f2b..e1a705a0 100644 --- a/README.md +++ b/README.md @@ -144,22 +144,23 @@ JSON configuration files can also be used to define the startup options for *mul ``` [ - { - // App1 - "uid": "app1", - "append": true, - "watch": true, - "script": "index.js", - "sourceDir": "/home/myuser/app1" - }, - { - // App2 - "uid": "app2", - "append": true, - "watch": true, - "script": "index.js", - "sourceDir": "/home/myuser/app2" - } + { + // App1 + "uid": "app1", + "append": true, + "watch": true, + "script": "index.js", + "sourceDir": "/home/myuser/app1" + }, + { + // App2 + "uid": "app2", + "append": true, + "watch": true, + "script": "index.js", + "sourceDir": "/home/myuser/app2", + "args": ["--port", "8081"] + } ] ``` diff --git a/lib/forever/cli.js b/lib/forever/cli.js index 4dd1048d..6bf09139 100644 --- a/lib/forever/cli.js +++ b/lib/forever/cli.js @@ -209,6 +209,7 @@ var getOptions = cli.getOptions = function (file) { 'sourceDir', 'workingDir', 'uid', 'watchDirectory', 'watchIgnore', 'killTree', 'killSignal', 'id' ], + specialKeys = ['script', 'args'], configs; // @@ -221,7 +222,10 @@ var getOptions = cli.getOptions = function (file) { configs = configs.map(function (conf) { var mut = Object.keys(conf) .reduce(function (acc, key) { - if (~configKeys.indexOf(key) || key === 'script') { acc[key] = conf[key]; } + if (~configKeys.indexOf(key) || ~specialKeys.indexOf(key)) { + acc[key] = conf[key]; + } + return acc; }, {}); diff --git a/test/core/start-stop-json-array-test.js b/test/core/start-stop-json-array-test.js index 495a06c3..6e9184ec 100644 --- a/test/core/start-stop-json-array-test.js +++ b/test/core/start-stop-json-array-test.js @@ -10,6 +10,8 @@ var assert = require('assert'), path = require('path'), fs = require('fs'), vows = require('vows'), + async = require('utile').async, + request = require('request'), forever = require('../../lib/forever'), runCmd = require('../helpers').runCmd; @@ -31,6 +33,22 @@ vows.describe('forever/core/start-stop-json-array').addBatch({ } } } +}).addBatch({ + "When the script is running": { + "request to both ports": { + topic: function () { + async.parallel({ + one: async.apply(request, { uri: 'http://localhost:8080', json: true }), + two: async.apply(request, { uri: 'http://localhost:8081', json: true }) + }, this.callback); + }, + "should respond correctly": function (err, results) { + assert.isNull(err); + assert.isTrue(!results.one[1].p); + assert.equal(results.two[1].p, 8081); + } + } + } }).addBatch({ "When the script is running" : { "try to stopall" : { diff --git a/test/fixtures/server.js b/test/fixtures/server.js index a386de20..2054f19d 100644 --- a/test/fixtures/server.js +++ b/test/fixtures/server.js @@ -2,12 +2,12 @@ var util = require('util'), http = require('http'), argv = require('optimist').argv; -var port = argv.p || argv.port || 80; +var port = argv.p || argv.port || 8080; http.createServer(function (req, res) { console.log(req.method + ' request: ' + req.url); res.writeHead(200, {'Content-Type': 'text/plain'}); - res.write('hello, i know nodejitsu.'); + res.write(JSON.stringify(argv)); res.end(); }).listen(port); diff --git a/test/fixtures/server.json b/test/fixtures/server.json index 9fdebbcc..17639071 100644 --- a/test/fixtures/server.json +++ b/test/fixtures/server.json @@ -1,6 +1,6 @@ { - "uid": "server", - "append": true, - "script": "server.js", - "sourceDir": "./test/fixtures" + "uid": "server", + "append": true, + "script": "server.js", + "sourceDir": "./test/fixtures" } diff --git a/test/fixtures/server2.js b/test/fixtures/server2.js deleted file mode 100644 index f61ca8c5..00000000 --- a/test/fixtures/server2.js +++ /dev/null @@ -1,16 +0,0 @@ -var util = require('util'), - http = require('http'), - argv = require('optimist').argv; - -var port = argv.p || argv.port || 81; - -http.createServer(function (req, res) { - console.log(req.method + ' request: ' + req.url); - res.writeHead(200, {'Content-Type': 'text/plain'}); - res.write('hello, i know nodejitsu.'); - res.end(); -}).listen(port); - -/* server started */ -util.puts('> hello world running on port ' + port); - diff --git a/test/fixtures/servers.json b/test/fixtures/servers.json index 81c770a3..d97e0e67 100644 --- a/test/fixtures/servers.json +++ b/test/fixtures/servers.json @@ -1,14 +1,15 @@ [ - { - "uid": "server1", - "append": true, - "script": "server.js", - "sourceDir": "./test/fixtures" - }, - { - "uid": "server2", - "append": true, - "script": "server2.js", - "sourceDir": "./test/fixtures" - } + { + "uid": "server1", + "append": true, + "script": "server.js", + "sourceDir": "./test/fixtures" + }, + { + "uid": "server2", + "append": true, + "script": "server.js", + "sourceDir": "./test/fixtures", + "args": ["-p", 8081] + } ] diff --git a/test/worker/multiple-workers-test.js b/test/worker/multiple-workers-test.js index de995bba..72f545aa 100644 --- a/test/worker/multiple-workers-test.js +++ b/test/worker/multiple-workers-test.js @@ -22,12 +22,12 @@ var children = [], function assertRunning(port, i) { return { topic: function () { - request('http://127.0.0.1:' + port, this.callback); + request({ uri: 'http://127.0.0.1:' + port, json: true }, this.callback); }, "should respond with `i know nodejitsu`": function (err, res, body) { assert.isNull(err); assert.equal(res.statusCode, 200); - assert.equal(body, 'hello, i know nodejitsu.'); + assert.equal(body.port, port); }, "stop the child process": function () { children[i].stop();