-
Notifications
You must be signed in to change notification settings - Fork 71
/
browser.js
46 lines (39 loc) · 1.47 KB
/
browser.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright IBM Corp. 2014,2019. All Rights Reserved.
// Node module: loopback-boot
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
'use strict';
const Bootstrapper = require('./lib/bootstrapper');
/**
* 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()`.
* @param {Object|string} [options] options as described in
* `boot.compileToBrowserify`.
*
* @header boot(app)
*/
exports = module.exports = function bootBrowserApp(app, options, callback) {
// Only using options.id to identify the browserified bundle to load for
// this application. If no Id was provided, load the default bundle.
let moduleName = 'loopback-boot#instructions';
const appId = options && typeof options === 'object' && options.appId;
if (appId)
moduleName += '-' + appId;
// The name of the module containing instructions
// is hard-coded in lib/bundler
const instructions = require(moduleName);
const bootstrapper = new Bootstrapper(options);
bootstrapper.phases = ['starting', 'start', 'started'];
const context = {
app: app,
instructions: instructions,
};
return bootstrapper.run(context, callback);
};