Page Contents

Migrating from LoopBack version 3 to version 4 is a big task because so many things have changed between the versions. To make this process easier, we implemented a feature allowing users to run their existing LoopBack 3 application as a component of the new LoopBack 4 project.

By adding your application this way, the application’s REST API is included in the OpenAPI spec provided by the LoopBack 4 application. This also means that the LoopBack 3 application’s models can be used with the LoopBack 4 REST API Explorer.

Mounting the LoopBack 3 Application in a LoopBack 4 Project

Follow this tutorial that goes through the full steps to mount your application.

To see an example of a mounted application, see lb3-application which mounts the CoffeeShop example, built from LoopBack 3, in a LoopBack 4 project.

Scaffolded LoopBack 4 apps come with a migrate npm script, which can be run using npm run migrate. This command will migrate all the LoopBack 3 models along with the LoopBack 4 models.

Options

Lb3AppBooterComponent comes with the option to either mount the full LoopBack 3 application or only the rest routes. Default mode is the full application (fullApp).

src/application.ts

this.bootOptions = {
  lb3app: {
    // only REST routes are mounted
    mode: 'restRouter',
  },
};

To change the path where the main LoopBack 3 application server file is stored, you can modify the path. Default path is ../lb3app/server/server.

src/application.ts

this.bootOptions = {
  lb3app: {
    // server file is found under this path
    path: '../coffee-shop/server/server',
  },
};

Finally, you can modify the restApiRoot when only mounting the rest router of your LoopBack 3 application. Default is restApiRoot is /api.

src/application.ts

this.bootOptions = {
  lb3app: {
    mode: 'restRouter',
    restApiRoot: '/coffees',
  },
};