Example of using middleware with LoopBack.
Page Contents
Note: This page was generated from the
loopback-example-middleware/README.md.
loopback-example-middleware
$ git clone git@github.com:strongloop/loopback-example-middleware.git
$ cd loopback-example-middleware
$ npm install
$ node .
How do you serve static content via static middleware?
- Add static middleware to the files property in middleware.json
- Delete
server/boot/root.js
. - Create
client/index.html
- Start the server via
node .
and browse tolocalhost:3000
. You should seehello world
being served.
How do you create a custom error message for all errors?
- Create a single function that all errors are passed to.
- Set
app.get('remoting').errorHandler
to call a custom error handler. - Create a
custom error middleware
to handle errors not thrown by theloopback.rest()
middleware.
Note: you must register your custom error handler in the middleware.json config file.