Merge branch 'master' into 2.0

Conflicts:
	index.js
	package.json
This commit is contained in:
Miroslav Bajtoš 2014-06-16 19:49:45 +02:00
commit 0a0a6f5d01
3 changed files with 30 additions and 9 deletions

View File

@ -7,6 +7,10 @@ var addInstructionsToBrowserify = require('./lib/bundler');
* Initialize an application from an options object or
* a set of JSON and JavaScript files.
*
* > **NOTE**: This module is primarily intended for use with LoopBack 2.0.
* It _does_ work with LoopBack 1.x applications, but
* none of the LoopBack 1.x examples or generated code (scaffolding) use it.
*
* This function takes an optional argument that is either a string
* or an object.
*
@ -37,11 +41,11 @@ var addInstructionsToBrowserify = require('./lib/bundler');
* dataSource and extra relations. To define a model, create a per-model
* JSON file in `models/` directory.
*
* **NOTE:** mixing `app.boot()` and `app.model(name, config)` in multiple
* files may result in models being **undefined** due to race conditions.
* To avoid this when using `app.boot()` make sure all models are passed
* as part of the `models` configuration.
*
* **NOTE:** Mixing `bootLoopBackApp(app, bootConfig)` and
* `app.model(name, modelConfig)` in multiple
* files may result in models being undefined due to race conditions.
* To avoid this when using `bootLoopBackApp()` make sure all models are passed
* as part of the `models` definition.
*
* Throws an error if the config object is not valid or if boot fails.
*

View File

@ -1,6 +1,7 @@
var assert = require('assert');
var _ = require('underscore');
var loopback = require('loopback');
var semver = require('semver');
var debug = require('debug')('loopback:boot:executor');
/**
@ -13,6 +14,8 @@ var debug = require('debug')('loopback:boot:executor');
*/
module.exports = function execute(app, instructions) {
assertLoopBackVersion(app);
setHost(app, instructions);
setPort(app, instructions);
setApiRoot(app, instructions);
@ -26,6 +29,22 @@ module.exports = function execute(app, instructions) {
enableAnonymousSwagger(app, instructions);
};
function assertLoopBackVersion(app) {
var RANGE = '1.x || 2.x';
// app.loopback was introduced in 1.9.0
var loopback = app.loopback || {};
var version = loopback.version || '1.0.0';
if (!semver.satisfies(version, RANGE)) {
throw new Error(
'The `app` is powered by an incompatible loopback version %s. ' +
'Supported versions: %s',
loopback.version || '<1.9',
RANGE);
}
}
function setHost(app, instructions) {
//jshint camelcase:false
var host =

View File

@ -10,7 +10,7 @@
],
"repository": {
"type": "git",
"url": "https://github.com/loobpack/loopback-boot"
"url": "https://github.com/strongloop/loopback-boot"
},
"main": "index.js",
"browser": "browser.js",
@ -25,6 +25,7 @@
"dependencies": {
"commondir": "0.0.1",
"debug": "^0.8.1",
"semver": "^2.3.0",
"toposort": "^0.2.10",
"underscore": "^1.6.0"
},
@ -35,8 +36,5 @@
"supertest": "^0.13.0",
"fs-extra": "^0.9.1",
"browserify": "^4.1.8"
},
"peerDependencies": {
"loopback": "1.x || 2.x"
}
}