LoopBack 3 has reached end of life. We are no longer accepting pull requests or providing support for community users. The only exception is fixes for critical bugs and security vulnerabilities provided as part of support for IBM API Connect customers. We urge all LoopBack 3 users to migrate their applications to LoopBack 4 as soon as possible. Learn more about LoopBack's long term support policy.

Middleware example app

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?

  1. Add static middleware to the files property in middleware.json
  2. Delete server/boot/root.js.
  3. Create client/index.html
  4. Start the server via node . and browse to localhost:3000. You should see hello world being served.

How do you create a custom error message for all errors?

  1. Create a single function that all errors are passed to.
  2. Set app.get('remoting').errorHandler to call a custom error handler.
  3. Create a custom error middleware to handle errors not thrown by the loopback.rest() middleware.

Note: you must register your custom error handler in the middleware.json config file.


More LoopBack examples

Tags: example_app

AltStyle によって変換されたページ (->オリジナル) /