2019-05-07 13:12:54 +00:00
|
|
|
// Copyright IBM Corp. 2014,2019. All Rights Reserved.
|
2016-05-06 04:52:36 +00:00
|
|
|
// Node module: loopback-boot
|
|
|
|
// This file is licensed under the MIT License.
|
|
|
|
// License text available at https://opensource.org/licenses/MIT
|
|
|
|
|
2017-05-08 21:48:48 +00:00
|
|
|
'use strict';
|
|
|
|
|
2016-04-27 22:55:57 +00:00
|
|
|
var Bootstrapper = require('./lib/bootstrapper');
|
2014-06-03 12:08:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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`.
|
|
|
|
*
|
|
|
|
* @param {Object} app The loopback app to boot, as returned by `loopback()`.
|
2015-03-13 01:03:35 +00:00
|
|
|
* @param {Object|string} [options] options as described in
|
|
|
|
* `boot.compileToBrowserify`.
|
2014-06-03 12:08:34 +00:00
|
|
|
*
|
2014-07-07 18:53:39 +00:00
|
|
|
* @header boot(app)
|
2014-06-03 12:08:34 +00:00
|
|
|
*/
|
|
|
|
|
2016-04-27 22:55:57 +00:00
|
|
|
exports = module.exports = function bootBrowserApp(app, options, callback) {
|
2015-03-13 01:03:35 +00:00
|
|
|
// Only using options.id to identify the browserified bundle to load for
|
|
|
|
// this application. If no Id was provided, load the default bundle.
|
|
|
|
var moduleName = 'loopback-boot#instructions';
|
2016-04-27 22:55:57 +00:00
|
|
|
var appId = options && typeof options === 'object' && options.appId;
|
|
|
|
if (appId)
|
|
|
|
moduleName += '-' + appId;
|
2015-03-13 01:03:35 +00:00
|
|
|
|
2014-06-03 12:08:34 +00:00
|
|
|
// The name of the module containing instructions
|
|
|
|
// is hard-coded in lib/bundler
|
2015-03-13 01:03:35 +00:00
|
|
|
var instructions = require(moduleName);
|
2016-04-27 22:55:57 +00:00
|
|
|
|
|
|
|
var bootstrapper = new Bootstrapper(options);
|
|
|
|
bootstrapper.phases = ['starting', 'start', 'started'];
|
|
|
|
var context = {
|
|
|
|
app: app,
|
|
|
|
instructions: instructions,
|
|
|
|
};
|
|
|
|
return bootstrapper.run(context, callback);
|
2014-06-03 12:08:34 +00:00
|
|
|
};
|
|
|
|
|