Neutral, Plus or Minus

    This package has been deprecated

    Author message:

    This version of Optic is now deprecated. Please check the repository at https://github.com/opticdev/optic for the latest information.

    @useoptic/hapi-middleware

    0.0.6 • Public • Published

    @useoptic/hapi-middleware

    NPM GitHub Workflow Status

    This module is an hapi plugin 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/.

    Install

    npm install @useoptic/hapi-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 hapi server.

    const Hapi = require('@hapi/hapi')
    const { OpticPlugin } = require('@useoptic/hapi-middleware')
    
    const init = async () => {
      const server = Hapi.server({
        port: 3001,
        host: 'localhost'
      })
    
      await server.register({
        plugin: OpticPlugin,
        options: {
          enabled: true
        }
      })
      server.route({
        method: ['GET', 'POST'],
        path: '/',
        handler: (request, h) => {
          return 'Hello World! ' + Math.random()
        }
      })
    
      await server.start()
      console.log('Server running on %s', server.info.uri)
    }
    
    process.on('unhandledRejection', (err) => {
      if (err) {
        console.log('ERROR')
        console.log(err)
        process.exit(1)
      }
    })
    
    init()

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

    api exec "node <your hapi server>"

    License

    This software is licensed under the MIT license.

    Keywords

    none

    Install

    npm i @useoptic/hapi-middleware

    DownloadsWeekly Downloads

    8

    Version

    0.0.6

    License

    MIT

    Unpacked Size

    28 kB

    Total Files

    12

    Last publish

    Collaborators

    • niclim
    • acunniffe
    • opticbot
    • jaaprood
    • notnmeyer