Skip to content

Commit 215e99a

Browse files
committed
getting bin/launch to work
1 parent 387d396 commit 215e99a

File tree

6 files changed

+29
-22
lines changed

6 files changed

+29
-22
lines changed

bin/launch

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
#!/usr/bin/env node
22
/**
33
* Spawns one or more apps on multiple ports listed in apps' settings files.
4-
* TODO: Allow overriding settings.
5-
* TODO: This file probably needs review and refactoring.
6-
* TODO: Accept a 'copies' arg to specify how many instance of each app to launch.
7-
* (see sonos-js/app.js for example).
84
*/
95
var clc = require('cli-color');
106
var path = require('path');
117
var fs = require('fs');
128
var spawn = require('child_process').spawn;
9+
var Settings = require('settings');
10+
var config = new Settings(require('../config'));
1311

1412
var help = 'Usage: launch [app_name1 [app_name2]](required))';
1513
var argv = require('optimist')
@@ -27,13 +25,11 @@ if (argv._.length === 0) {
2725
process.env.NODE_ENV = process.env.NODE_ENV || argv.e || 'dev';
2826
var ENV = process.env.NODE_ENV;
2927

30-
require('../src/index.js');
28+
require('../lib');
3129

32-
// TODO: what path and file name for this combined log?
33-
// Or should it not be combined?
3430
function start_detached(module_name, app_port) {
35-
var out = fs.openSync(__dirname + '/../logs/multi.log', 'a');
36-
var err = fs.openSync(__dirname + '/../logs/multi.log', 'a');
31+
var out = fs.openSync(__dirname + '/../log/multi.log', 'a');
32+
var err = fs.openSync(__dirname + '/../log/multi.log', 'a');
3733
var start_opts = [module_name, '--port', app_port, '-e', ENV];
3834
var spawn_opts = {
3935
detached: true,
@@ -49,9 +45,9 @@ function start_detached(module_name, app_port) {
4945
function get_app_ports(app_settings) {
5046
var ports = [];
5147

52-
if (app_settings && app_settings[ENV] && app_settings[ENV].server && app_settings[ENV].server.port) {
53-
var starting_port = app_settings[ENV].server.port;
54-
var nbr_of_proxies = app_settings[ENV].server.proxies;
48+
if (app_settings && app_settings.port) {
49+
var starting_port = app_settings.port;
50+
var nbr_of_proxies = app_settings.proxies;
5551
for (var i = 0; i < nbr_of_proxies; i++) {
5652
ports.push(starting_port + i);
5753
}
@@ -60,15 +56,15 @@ function get_app_ports(app_settings) {
6056
return ports;
6157
}
6258

63-
argv._.forEach(function(module) {
64-
var app_settings = require('../settings/' + module).settings;
59+
argv._.forEach(function(app_name) {
60+
var app_settings = config.apps[app_name];
6561
var ports = get_app_ports(app_settings);
6662

6763
if (ports.length === 0) {
68-
throw new Error("Failed to get port from settings for module: " + module);
64+
throw new Error("Failed to get port from settings for app: " + app_name);
6965
}
7066

7167
ports.forEach(function(app_port) {
72-
start_detached(module, app_port);
68+
start_detached(app_name, app_port);
7369
});
7470
});

bin/start

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var log_red = function(msg) {
1414
var help = 'Usage: $0 [app_name1, [app_name2]] -e dev';
1515
var optimist = require('optimist');
1616
argv = optimist
17-
.boolean(['port'])
17+
.string(['port'])
1818
.alias('port', 'p')
1919
.describe('port', 'port to run server(s) on')
2020
.string('env')
@@ -34,7 +34,7 @@ var app = require('../lib/app')();
3434

3535
if (port) {
3636
if (isNaN(parseInt(port, 10))) {
37-
throw "Invalid port number";
37+
throw new Error("Invalid port number: " + port);
3838
}
3939
} else {
4040
port = 8080;

config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ module.exports = {
22
common: {
33
server: {
44
port: 8080
5+
},
6+
7+
apps: {
8+
users: {
9+
port: 12100,
10+
proxies: 2
11+
}
512
}
613
},
714

lib/models/user.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
function User(args) {
2-
this.id = args.id;
2+
this.id = args.id || 123;
3+
this.username = args.username;
34
}
45

56
User.create = function (args, cb) {

lib/server/app_server.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var logger = new Logger({
99
name: 'app',
1010
streams: [
1111
{
12-
path: '/tmp/app.log',
12+
path: log_path,
1313
level: 'debug'
1414
}
1515
]
@@ -20,6 +20,7 @@ function AppServer(config, options) {
2020
self.config = config;
2121
self.started = false;
2222

23+
// TODO:
2324
//var uncaught_exception_handler = require('./uncaught_exception_handler')({app_name: app_name});
2425
if (!config) { throw new Error("AppServer requires a config object"); }
2526

test/acceptance/users/create.acceptance.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ describe("Feature: User creation", function () {
1111
context("Scenario: using a username and password", function () {
1212
context("Given a username does not already exist", function () {
1313
context("When an API client POSTs to /users with a valid username and password", function () {
14+
var params;
1415
var response;
1516
var raw_res;
1617

1718
before(function (done) {
18-
var params = {
19+
params = {
1920
username: support.random.string(),
2021
password: support.random.string()
2122
};
@@ -32,8 +33,9 @@ describe("Feature: User creation", function () {
3233
assert.strictEqual(raw_res.statusCode, 200);
3334
});
3435

35-
it("And the response data should include the user's ID", function () {
36+
it("And the response data should include the user's ID and username", function () {
3637
assert.ok(response.data.id);
38+
assert.equal(response.data.username, params.username);
3739
});
3840
});
3941
});

0 commit comments

Comments
 (0)