Commit Graph

31 Commits

Author SHA1 Message Date
yorkie d249b15ce0 add env folder for boot 2015-09-29 12:31:46 +08:00
Simon Ho 43042905af Add config variable checks
- Check for config variables defined as functions
- Check for config variables that are undefined
2015-08-31 17:53:27 -07:00
Hage Yaapa 1b491dee85 Resolve ${var} values in component-config.json
App variables can now be specified in component-config.json using
the ${var} format. The value of var is looked up using app.get().

This allows loopback explorer and other loopback components which
require app variables, to be loaded declaratively using
component-config.json.
2015-08-28 11:49:46 +05:30
Hack Sparrow 8b475a97b2 Resolve ${var} values in middleware.json
App variables can now be specified in middleware.json using the ${var}
format. The value of var is looked up using app.get().

This allows loopback.rest and other loopback middleware which require
app variables, to be loaded declaratively using middleware.json.
2015-08-25 18:42:47 +05:30
Jonathan Sheely 44f733f59f Support iisnode using named pipes as PORT value
Port can't be number checked to support iisnode. Using a parseInt()
or number isNumber function won't work if we want to support iisnode
which uses named pipes for ports (ex. \\.\pipe\mypipe)
2015-05-29 10:34:05 +02:00
Pradnya Baviskar 53f51820f5 support 'mixinsources' option
- By default looks for mixinsources in  directory

- Loads only mixins used through models
2015-05-07 14:35:55 +05:30
Pradnya Baviskar 9bb988713e add support for mixins
- [mixinDirs]: List of directories to look for files
 containing model mixin definition.
2015-04-24 12:42:56 +05:30
Miroslav Bajtoš e5fd8c7975 executor: fix port lookup
Use the global `isFinite` function to find the first valid port
number. This is the same behaviour as `_.isFinite` in lodash@2.x.

As a result, only values that are a valid number are accepted, e.g.
"0" is accepted but "0xy" is not.
2015-04-23 08:51:24 +02:00
Miroslav Bajtoš acf1868ba4 Support per-application registry of models 2015-04-09 17:56:56 +02:00
Pradnya Baviskar 2c4b6f06a4 Add feature to disable component 2015-03-10 15:03:20 +05:30
Pradnya Baviskar 872889423a Fix test for different line endings on Windows 2015-03-05 09:53:28 +05:30
Simon Ho 276391811a Refactor unit test assertions to be more specific
- Change `process.bootingFlagSet` assertion from `ok()` to `true()`
- Change `app.booting` assertion from `not.be.ok()` to `false()`
2015-02-23 13:10:12 -08:00
Simon Ho e89a60c45c Add unit test to verify `app.booting flag status
- Ensure `app.booting` is initially `undefined`
- Ensure `app.booting` is set to true during boot execution
- Ensure `app.booting` is set to false upon boot completion
2015-02-20 13:51:53 -08:00
Clark Wang 6424534831 executor: pass correct `this` to middleware
Fix the bug "can't configure passport#initialize in middleware.json"
2015-02-02 18:54:22 +01:00
Samuel Reed 30a7b6d9b8 Don't swallow error when a sub-dependency doesn't resolve.
This prevents an occurence where an error is completely swallowed if a script
required by loopback-boot has a bad require() call. The script is never ran
but execution continues.
2015-01-13 10:23:54 +01:00
Miroslav Bajtoš c47bde9281 Merge pull request #77 from strongloop/feature/add-boot-completion-check
Add "booting" flag and emit "booted" event
2015-01-07 16:41:29 +01:00
Simon Ho 1f7d8e56e8 Add "booting" flag and emit "booted" event 2015-01-06 21:27:32 -08:00
Miroslav Bajtoš f8247be23c Configure components via `component-config.json`
Load configuration of components from `component-config`
and configure all components as specified.

Sample JSON:

    {
      "loopback-component-foobar": {
        "option1": "value1",
        "option2": "value2"
      }
    }

The component is expected to export the following function:

    module.exports = function(app, options) { /* ... */ };
2015-01-06 14:00:26 +01:00
Raymond Feng 2f72006c88 Implement shorthand notation for middleware paths
When the middleware name (path) is in the format {module}#{filename},
loopback-boot resolves the path by trying multiple locations and
using the first one that exists:

 - {module} and check the {filename} property of the exports
     -> e.g. loopback.rest
- {module}/server/middleware/{filename}
    -> e.g. loopback/server/middleware/rest
 - {module}/middleware/{filename}
    -> e.g. loopback/middleware/rest

Values in any other format will bypass this resolution algorithm and
they will be used in the original form:

 - a full path in a module: loopback/server/middleware/rest
 - a relative path: ./middleware/custom, ./custom, ../logger
 - an absolute path: /usr/local/lib/node_modules/compression
2014-11-25 11:43:00 +01:00
Miroslav Bajtoš 1114bc9227 Load middleware and phases from `middleware.json`
Sample JSON:

        {
          "routes:before": {
            "morgan": {
              "params": ["dev"]
            }
          },
          "routes": {
            "loopback/server/middleware/rest": {
            }
          },
          "subapps": {
            "./adminer": {
            },
          }
        }

The JSON file can be customized using the usual conventions:
  - middleware.local.{js|json}
  - middleware.{env}.{js|json}

It is also possible to mount the same middleware in the same phase
multiple times with different configuration.

Example config:

    {
      "auth": {
        "oauth2": [
          {
            "params": "first"
          },
          {
            "params": "second"
          }
        ]
      },
    });
2014-11-19 09:45:04 +01:00
Miroslav Bajtoš 5b5071864b Add jscs style check, fix violations found 2014-11-13 15:54:59 +01:00
Miroslav Bajtoš e2aff71bf9 Use `chai` instead of `must`
As of 1.10, chai supports nonary assertions, there are no more reasons
for using a different variant.
2014-11-13 15:31:35 +01:00
Miroslav Bajtoš 26abb43ad4 Skip definitions of built-in loopback models
LoopBack built-in models are special: they follow the loopback-boot
structure and provide `common/models/{name}.json` files, but they are
also automatically loaded (created) by loopback.

This change modifies `executor` to recognize built-in models and do not
redefine them.
2014-10-21 18:10:22 +02:00
Raymond Feng 94cb4d6342 Add support for async boot scripts 2014-10-09 12:18:36 -07:00
Miroslav Bajtoš c4b09c6b7a executor: remove `Base` arg from model function
Simplify the contract for functions exported by `models/*.js` files
by removing the second argument `Base`. The base class can be accessed
using `ModelCtor.base`.

An updated example of a model js file:

```js
module.exports = function(Customer) {
  Customer.setup = function() {
    Customer.base.setup.apply(this, arguments);
    // etc.
  };
};
```
2014-07-22 10:59:50 +02:00
Miroslav Bajtoš ac16d92a8b Rename `app.json` to `config.json`
The new loopback project layout adds a concept of components like
'rest server' and 'isomorphic client', each component having its own set
of boot files. The name `app.json` is confusing, since it is configuring
a component, not the app (which is the whole project).
2014-06-25 08:18:04 +02:00
Miroslav Bajtoš ef72efa70b executor: Split model boot into two phases
In the first phase, all models are defined.

In the second phase, models are configured, attached to data-sources
and exposed on the app object.

This way when the `attached` Model event is emitted, all models are
already defined and thus a listener can get reference of any other
model used in the app.
2014-06-16 16:41:12 +02:00
Miroslav Bajtoš a204fdc1c9 Rework model configuration
Rework the way how models are configured, the goal is to allow
loopback-boot to automatically determine the correct order
of the model definitions to ensure base models are defined
before they are extended.

 1. The model .js file no longer creates the model, it exports
 a config function instead:

  ```js
  module.exports = function(Car, Base) {
    // Car is the model constructor
    // Base is the parent model (e.g. loopback.PersistedModel)

    Car.prototype.honk = function(duration, cb) {
      // make some noise for `duration` seconds
      cb();
    };
  };
  ```

 2. The model is created by loopback-boot from model .json file.
  The .js file must have the same base file name.

 3. The `boot()` function has a new parameter `modelSources` to
  specify the list of directories where to look for model definitions.
  The parameter defaults to `['./models']`.

As a side effect, only models configured in `models.json` and their
base clases are defined. This should keep the size of the browserified
bundle small, because unused models are not included.
2014-06-13 19:40:52 +02:00
Miroslav Bajtoš 43993bf975 Remove auto-attach.
Breaking change.

The bootstrapper no longer calls `loopback.autoAttach`. Applications
have to explicitly configure datasources for their models
via `models.json`.
2014-06-10 09:24:16 +02:00
Miroslav Bajtoš 47b5bb5f5c Change models.json to configure existing models
Breaking change.

In the new 2.x project layout, definition of loopback Models is out of
scope of the boot process. The bootstrapper only configures existing
models - attaches them to a dataSource and the app object.
2014-06-10 09:21:15 +02:00
Miroslav Bajtoš b14800416a Split the boot process into two steps
Split bootLoopBackApp into two steps:
 - compile
 - execute

Most of the changes are just shuffling the existing code around.

What has changed:

 - `loopback.autoAttach()` is called after `models/*` are required.
   The calls were made in the opposite order before this commit.
2014-06-03 08:13:14 +02:00