Socket
Socket
Sign inDemoInstall

@useoptic/express-middleware

Package Overview
Dependencies
81
Maintainers
5
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @useoptic/express-middleware

NodeJS middleware for using Optic within ExpressJS


Version published
Weekly downloads
155
increased by26.02%
Maintainers
5
Install size
2.40 MB
Created
Weekly downloads
 

Readme

Source

@useoptic/express-middleware

NPM GitHub Workflow Status

This module is an Express middleware using @useoptic/optic-node-sdk to capture and format HTTP data to send to Optic. We have a list of middleware available for some frameworks, if we are missing the framework join our community and suggest the next framework or develop it with us.

Requirements

The module requires @useoptic/cli to be installed, instructions on installing it are available https://www.useoptic.com/docs/.

It also requires something like body-parser to be used as part of the middleware stack to access the body of the HTTP requests within Express

Install

npm install @useoptic/express-middleware

Usage

The middleware takes a configuration object and captures traffic in the background as long as @useoptic/cli is installed.

Configuration

All options are optional for easier configuration in your application

  • enabled: boolean (defaults to false) Programmatically control if capturing data and sending it to Optic
  • uploadUrl: string (defaults to process.env.OPTIC_LOGGING_URL) The URL to Optics capture URL, if left blank it will expect OPTIC_LOGGING_URL environment variable set by the Optic CLI
  • console: boolean (defaults to false) Send to stdout/console for debugging
  • framework: string (defaults to '') Additional information to inform Optic of where it is capturing information

Example

Using a basic Express server proxying to httpbin for easy endpoints

const express = require('express')
const bodyParser = require('body-parser')
const { createProxyMiddleware } = require('http-proxy-middleware');
const { OpticMiddleware } = require('@useoptic/express-middleware');

const app = express()
const port = 3000

app.use(bodyParser())
app.use(OpticMiddleware({
    enabled: true,
}))

app.use('/', createProxyMiddleware({ target: 'https://httpbin.org', changeOrigin: true }));

app.listen(port, () => {
  console.log(`Example app listening at http://localhost:${port}`)
})

To start capturing data from the SDK, run your application with

api exec "node <your express server>"

License

This software is licensed under the MIT license.

FAQs

Last updated on 20 Jul 2021

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc