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.
If the argument is a string, then it sets the application root directory based on the string value. Then it:
Creates DataSources from the datasources.json
file in the application
root directory.
Creates Models from the models.json
file in the application
root directory.
If the argument is an object, then it looks for model
, dataSources
,
and appRootDir
properties of the object.
If the object has no appRootDir
property then it sets the current working
directory as the application root directory.
Then it:
Creates DataSources from the options.dataSources
object.
Creates Models from the options.models
object.
In both cases, the function loads JavaScript files in the /models
and
/boot
subdirectories of the application root directory with require()
.
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.
Name | Type | Description |
---|---|---|
app |
|
LoopBack application created by |
options |
String or Object
|
Boot options; If String, this is the application root directory; if object, has below properties. |
Name | Type | Description |
---|---|---|
appRootDir |
String
|
Directory to use when loading JSON and JavaScript files (optional).
Defaults to the current directory ( |
models |
Object
|
Object containing |
dataSources |
Object
|
Object containing |
modelsRootDir |
String
|
Directory to use when loading |
datasourcesRootDir |
String
|
Directory to use when loading |
env |
String
|
Environment type, defaults to |
Compile boot instructions and add them to a browserify bundler.
Name | Type | Description |
---|---|---|
options |
Object or String
|
as described in |
bundler |
Object
|
A browserify bundler created by |
The browser version of bootLoopBackApp
.
When loopback-boot is loaded in browser, the module exports this
function instead of bootLoopBackApp
.
The function expects the boot instructions to be included in
the browser bundle, see boot.compileToBrowserify
.
Name | Type | Description |
---|---|---|
app |
Object
|
The loopback app to boot, as returned by |