Socket
Book a DemoInstallSign in
Socket

jlocke-express-middleware

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jlocke-express-middleware

Express middleware to store requests metadata into a Elastic.

latest
Source
npmnpm
Version
0.0.15
Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

jlocke-express-middleware

Continuos integration NSP Status

Express middleware to store requests metadata to an Elastic instance. We use it in JLocke project and other internal ones.

Install

npm i --save jlocke-express-middleware

Use

Please visit the tests to see a full example. NOTES:

  • The "bodyParser" should be attached before the middleware to capture the body of the POST requests.
  • Routes need to be defined after connecting this middleware to Express.

async jLocke.init(uri, opts) -> Promise

The middleware setup expects:

  • uri (string) - The database uri to connect to.
  • opts (object) - DB optional values:
    • trace (boolean) - To enable Elastic tracing. (default: false)
    • indexRequests (string) - Name of the Elastic index to store the requests info. (default: "api-requests-MM-DD-YYY")
    • typeRequests (string) - Elastic type of the element to store the requests info. (default: "requests")
    • indexErrors (string) - Name of the Elastic index to store the errors info. (default: "api-errors-MM-DD-YYY")
    • typeErrors (string) - Elastic type of the element to store the errors info. (default: "errors")

async jLocke.error(message, error, opts) -> Promise

To track the errors, ie: uncaughException, unhandledPromise. The middleware setup expects:

  • message (string) - Custom error message.
  • error (object) - JavaScript Error object.
  • opts (object) - Optional values:
    • userId (string) - User identifier to trace the error.

jLocke.express(opts) -> function

To track the Express requests info. The middleware expects to receive the next parameters. Please visit the tests for more details.

  • opts (object) - Optional values:
    • path (string) - To store only the requests through this subpath. (default: null)
    • hide (object) - To avoid to store sensitive data in the DB for a POST route. (default: {})
      • path (string) - The substring of the path to exlude stuff (ie: "login").
      • field (string) - Name of the object field to exclude (ie: "password").

Adding more parameters

Apart from the ones included by Express you can attach to the req the user ID to allow tracing:

  • userId (string) - User identifier.

Example here.

Developer guide

Please check this link before a contribution.

Keywords

loopback

FAQs

Package last updated on 18 Jan 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts