For current LoopBack 3 users who want to migrate to LoopBack 4, LoopBack 4offers a way to mount your LoopBack 3 application in a LoopBack 4 project. Byadding your application this way, the application’s REST API is included in theOpenAPI spec provided by the LoopBack 4 application. This also means that theLoopBack 3 application’s models can be used with the LoopBack 4 REST APIExplorer.
Mounting the LoopBack 3 Application in a LoopBack 4 Project
Note:
If you are not familiar with LoopBack 4, visitGetting started for an introduction.
Followthis tutorialthat goes through the full steps to mount your application.
To see an example of a mounted application, seelb3-applicationwhich mounts theCoffeeShop example,built from LoopBack 3, in a LoopBack 4 project.
Warning: An important thing to note is that LoopBack 3 applications produce Swagger(OpenAPI version 2), whereas LoopBack 4 produces OpenAPI version 3.Lb3AppBooterComponent
converts the Swagger spec from the mounted LoopBack 3application to OpenAPI v3 and adds it to the LoopBack 4 project’s OpenAPI v3spec.
Options
Lb3AppBooterComponent
comes with the option to either mount the full LoopBack 3 application or onlythe rest routes. Default mode
is the full application (fullApp
).
src/application.ts
this.bootOptions = {
lb3app: {
mode: 'restRouter', // only REST routes are mounted
},
};
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: {
path: '../coffee-shop/server/server', // server file is found under this path
},
};
Finally, you can modify the restApiRoot
when only mounting the rest router ofyour LoopBack 3 application. Default is restApiRoot
is /api
.
src/application.ts
this.bootOptions = {
lb3app: {
mode: 'restRouter',
restApiRoot: '/coffees',
},
};