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

express-x-hub

v1.0.4

Published

X-Hub-Signature Express Middleware

Downloads

8,159

Readme

Express X-Hub

Build Status Coverage Status

X-Hub-Signature Express.js Middleware. A compact way to validate X-Hub requests to ensure they have not been tampered with. Particularly useful for Facebook real-time updates and GitHub web hooks.

Getting Started

Install the middleware with this command:

npm install express-x-hub --save

Then add the middleware to Express.js. It needs to be one of the first and before bodyParser().

var xhub = require('express-x-hub');
app.use(xhub({ algorithm: 'sha1', secret: XHUB_SECRET_HERE }));
app.use(bodyParser());
app.use(methodOverride());

Where XHUB_SECRET_HERE is your platform's (facebook, github, etc) secret.

This will add some special sauce to your req object:

Request Additions

isXHub boolean

Is the request X-Hub. Allows you to early reject any messages without XHub content.

var isXHub = req.isXHub;
if(!isXHub) { return this.reject('No X-Hub Signature', req, res); }

isXHubValid req.isXHubValid()

Returns a boolean value. Validates the request body against the X-Hub signature using your secret.

var isValid = req.isXHubValid();
if(!isValid){ return this.reject('Invalid X-Hub Request', req, res); }

If its valid, then the request has not been tampered with and you are safe to process it.

Build

  1. npm test - Run tests.
  2. gulp - Lint and run tests.

Example

Some very simple examples can be found in the example dir.

Start the server:

node ./example/server.js

Curl in an emulated X-Hub post:

sh ./example/curl_valid.sh
>> { "success": "X-Hub Is Valid" }

sh ./example/curl_invalid.sh
>> { "error": "X-Hub Is Invalid" }

Options

secret string - required

X-Hub secret that is used to validate the request body against the signed X-HUB signature on the header.

algorithm string

Encryption algorithm used to generate the signature. Defaults to sha1.

limit string

Limit on the request body size. Defaults to 100kb.

encoding string

Encoding on the raw input stream. Defaults to utf8.

strict boolean

Strict demands on the JSON. Defaults to true.

reviver function

Reviver used during JSON.parse.