Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

brok

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

brok

Brotli encoder and decoder for hapi.js

  • 6.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6.6K
decreased by-32.7%
Maintainers
1
Weekly downloads
 
Created
Source

brok

Brotli encoder and decoder for hapi.js.

Node.js CI

Lead Maintainer - Gil Pedersen

Install

npm install brok

Example

Registration

Registration with custom quality default:

'use strict';

const Hapi = require('@hapi/hapi');
const Brok = require('brok');

const server = new Hapi.Server({ port: 3000, compression: { minBytes: 1 } });

const provision = async () => {

    server.route({
        method: 'GET',
        path: '/fetch',
        handler() {

            return 'ok';
        }
    });

    await server.register({
        plugin: Brok,
        options: {
            compress: { quality: 3 }
        }
    });

    await server.start();

    console.log('Server running at:', server.info.uri);
};

provision();

Usage

Once registered, brok enables the server to negotiate and handle the "br" encoding for compressible responses and uploads.

Registration options

brok accepts the following registration options:

  • compress - compression settings. Set to false to disable response compression using brotli.
    • quality - used to adjust compression speed vs quality from 0 to 11. Defaults to 5.
    • mode - compression mode. Available values:
      • 'generic' - default compression mode. Default value.
      • 'text' - optimize for UTF-8 formatted text input.
  • decompress - if true, also register the encoding for decompressing incoming payloads. Defaults to false.

Compression options

Route specific settings can be set using br object in the compression config. Eg.

server.route({
    method: 'GET',
    path: '/text',
    options: {
        handler() {

            return 'hello!';
        },
        compression: {
            br: { mode: 'text' }
        }
    }
});

Keywords

FAQs

Package last updated on 20 Mar 2024

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

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc