The Loopback team recently included the express-composition example for mounting the Loopback 4 Rest API in a regular Express application. See the full tutorial to do this on their official page here.
So, you can do something like this –
This also allowed adding Express style middleware before passing control to the Loopback application. It is especially useful for adding Express middleware to check access tokens, authentication etc.
app.use("/path", checkAccessTokenMiddleware ,loopbackApp.requestHandler);
Loopback 4 does provide something
I’ve modified the
Getting the Winston logger stream to log the Morgan HTTP requests was a bit tricky with Typescript, but I got it to work in the end. The log files generated by Winston are also split based on the logging levels. So, separate files are created for error, info and exceptions.
You can download the working example from my Git repository here. Feel free to poke around, and enhance it based on your needs.
You’ll also find
errorlogger controller internally uses the Winston logger to log an error.
To make changes, start with the
src/server.ts.It includes all the code for adding Express routes and middlewares.