Remove coercion from port check

This commit is contained in:
Ritchie Martori 2014-02-18 11:20:23 -08:00
parent a313d1d140
commit 500703e1fb
2 changed files with 35 additions and 9 deletions

View File

@ -7,6 +7,7 @@ var DataSource = require('loopback-datasource-juggler').DataSource
, compat = require('./compat') , compat = require('./compat')
, assert = require('assert') , assert = require('assert')
, fs = require('fs') , fs = require('fs')
, _ = require('underscore')
, RemoteObjects = require('strong-remoting') , RemoteObjects = require('strong-remoting')
, swagger = require('strong-remoting/ext/swagger') , swagger = require('strong-remoting/ext/swagger')
, stringUtils = require('underscore.string') , stringUtils = require('underscore.string')
@ -431,15 +432,16 @@ app.boot = function(options) {
process.env.npm_package_config_host || process.env.npm_package_config_host ||
app.get('host'); app.get('host');
appConfig.port = appConfig.port = _.find([
process.env.npm_config_port || process.env.npm_config_port,
process.env.OPENSHIFT_SLS_PORT || process.env.OPENSHIFT_SLS_PORT,
process.env.OPENSHIFT_NODEJS_PORT || process.env.OPENSHIFT_NODEJS_PORT,
process.env.PORT || process.env.PORT,
appConfig.port || appConfig.port,
process.env.npm_package_config_port || process.env.npm_package_config_port,
app.get('port') || app.get('port'),
3000; 3000
], _.isFinite);
appConfig.restApiRoot = appConfig.restApiRoot =
appConfig.restApiRoot || appConfig.restApiRoot ||

View File

@ -189,6 +189,12 @@ describe('app', function() {
var app = this.boot(); var app = this.boot();
assert.equal(app.get('host'), process.env.npm_config_host); assert.equal(app.get('host'), process.env.npm_config_host);
delete process.env.npm_config_host;
delete process.env.OPENSHIFT_SLS_IP;
delete process.env.OPENSHIFT_NODEJS_IP;
delete process.env.HOST;
delete process.env.npm_package_config_host;
process.env.npm_config_port = randomPort(); process.env.npm_config_port = randomPort();
process.env.OPENSHIFT_SLS_PORT = randomPort(); process.env.OPENSHIFT_SLS_PORT = randomPort();
process.env.OPENSHIFT_NODEJS_PORT = randomPort(); process.env.OPENSHIFT_NODEJS_PORT = randomPort();
@ -198,6 +204,12 @@ describe('app', function() {
var app = this.boot(); var app = this.boot();
assert.equal(app.get('host'), process.env.npm_config_host); assert.equal(app.get('host'), process.env.npm_config_host);
assert.equal(app.get('port'), process.env.npm_config_port); assert.equal(app.get('port'), process.env.npm_config_port);
delete process.env.npm_config_port;
delete process.env.OPENSHIFT_SLS_PORT;
delete process.env.OPENSHIFT_NODEJS_PORT;
delete process.env.PORT;
delete process.env.npm_package_config_port;
}); });
function randomHost() { function randomHost() {
@ -207,6 +219,18 @@ describe('app', function() {
function randomPort() { function randomPort() {
return Math.floor(Math.random() * 10000); return Math.floor(Math.random() * 10000);
} }
it('should honor 0 for free port', function () {
var app = loopback();
app.boot({app: {port: 0}});
assert.equal(app.get('port'), 0);
});
it('should default to port 3000', function () {
var app = loopback();
app.boot({app: {port: undefined}});
assert.equal(app.get('port'), 3000);
});
}); });
it('Instantiate models', function () { it('Instantiate models', function () {