npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

wsabi

v3.1.0

Published

HTTP-over-websocket layer for the Hapi web framework.

Downloads

5

Readme

Wsabi

Build Status Coverage Status

Wsabi is a layer which allows you to call Hapi http endpoints from websockets, basically serving as a bridge between Socket.io and Hapi's server.inject. It was originally built to be backwards compatible with the Sails.js websocket system, during a backend port.

Usage

To Wsabi, simply register it on your server.

server.register({ register: require('wsabi') }, function (err) {
    // ...
});

Options:

  • io defaults to an empty object. List of options to pass to the socket.io server,
  • cookies defaults to "true". Determines whether Wsabi should "manage" the session cookies for you - see the note below.
  • sticky defaults to []. Should be an array of headers you want to keep from the handshake and pass directly into the server. Setting sticky to ["x-forwarded-for"] may be useful. The client will not be able to overwrite these.
  • strip defaults to []. Should be an array of headers you don't care to send back down to the client over websockets.
  • errors is an object
    • required is the reply sent if sockets are required on the route, but it's accessed over HTTP. Defaults to a Boom.badRequest instance.
    • disabled is the reply sent if sockets are disabled on the route and it's attempted to be accessed over sockets. Defaults to a Boom.badRequest instance.

After this, you can then connect to your server using any supported client library, including:

Routes also have their own options that you can pass in the plugin config:

  • required defaults to false: setting it to true will cause an error to be sent if the socket is accessed over plain HTTP.
  • enabled defaults to true: setting it to false will cause an error to be sent if the socket is accessed over websockets.
  • errors object can be passed in for custom error overrides.
// Example of a route with wsabi disabled:
server.route({
    method: 'GET',
    path: '/',
    config: {
        plugins: { wsabi: { enabled: false }}
    }
    // ...
})

If you'd like to access the websocket itself in your request, you can access req.websocket. That may also be used for checking if a route is running under websockets.

You can also access the socket.io server directly after registration via server.plugins.wsabi.io.

A Note About Sessions

The session "state" is stored on the socket connection. Cookies passed in the initial Socket.io handshake request will be passed on automatically in every request on that socket. If a response includes a set-cookie header, we'll update the stored cookie jar, and if you send in a request with a Cookie header then the cookie jar will be updated appropriately.

You can disable handling of cookies by passing cookies: false in the plugin config. When disabled, only the cookies explicitly sent on each request will be used.

License

This software is MIT licensed, copyright 2016 by Beam Interactive, Inc.

Why the name?

Because it's Hapi websockets, and if you say "WS Hapi" quickly several times it sounds like "wasabi". Wasabi itself was already taken on npm, so we have wsabi! Oh, and because sushi is awesome.