Skip to content

Boot script ordering #61

Closed
Closed

Description

@raymondfeng

The scripts in server/boot are executed by the order of file names as of today.

There are a few use cases that require ordering.

  1. A boot script discovers models from a DB and exposes them as REST APIs. It needs to be executed before the api-explorer.
  2. An async script that needs to be executed after the system-level boot scripts. For example, if we add the following JS file into server/boot today, the express middleware chain will be messed up:

abc.js (this ensures the file name is sorted before rest-api.js, explorer.js)

module.exports = function(app, cb) {
  process.nextTick(cb);
}

In this case, boot(app, __dirname) returns before the rest-api.js is executed. As a consequence, urlNotFound and errHandler come before the rest handler.

// boot scripts mount components like REST API
boot(app, __dirname);

// -- Mount static files here--
// All static middleware should be registered at the end, as all requests
// passing the static middleware are hitting the file system
// Example:
//   var path = require('path');
//   app.use(loopback.static(path.resolve(__dirname, '../client')));

// Requests that get this far won't be handled
// by any middleware. Convert them into a 404 error
// that will be handled later down the chain.
app.use(loopback.urlNotFound());

// The ultimate error handler.
app.use(loopback.errorHandler());

Potential solutions:

  1. Formalize the file names as 01_first.js, 02_second.js for the scaffolded JS files
  2. Use phases (preferred)

In addition, we probably should move the urlNotFound/errorHandler middleware code to a boot script too.

Activity

  1. bajtos commented on Oct 24, 2014

    @bajtos
    Member

    My $0.02:

    A boot script discovers models from a DB and exposes them as REST APIs. It needs to be executed before the api-explorer.

    This should be fixed in explorer - see strongloop/loopback-component-explorer#22 and strongloop/loopback#686

    An async script that needs to be executed after the system-level boot scripts. For example, if we add the following JS file into server/boot today, the express middleware chain will be messed up.

    Good point. This is sort of an edge case problem introduced by #50, right?

    Potential solutions:
    Use phases (preferred)

    Yes please.

    In addition, we probably should move the urlNotFound/errorHandler middleware code to a boot script too.

    Alternatively we can register them with the appropriate middleware phase at the time and place where the middleware phases are defined.

  2. raymondfeng commented on Oct 24, 2014

    @raymondfeng
    MemberAuthor

    Phase is the magic pain killer 👍

  3. bajtos commented on Nov 2, 2018

    @bajtos
    Member

    In October 2018, LoopBack 4.0 GA was released. LoopBack 3 and its supporting modules have entered LTS mode. Per our Long Term Support Policy, this means new features are no longer accepted.

    I am closing this GitHub issue as "wont fix".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions