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 worldbeing 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').errorHandlerto call a custom error handler. - Create a
custom error middlewareto handle errors not thrown by theloopback.rest()middleware.
Note: you must register your custom error handler in the middleware.json config file.