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 🙏

© 2026 – Pkg Stats / Ryan Hefner

connect-spa-request-filter

v0.3.0

Published

Single Page Apps APIs request filter middleware for connect

Readme

Connect Single Page Apps Request Filter Middleware

A Node.js Connect framework middleware for Single Page Applications APIs that filters requests by type, intercepting requests that aren't of 'application/json' type serving them the application shell HTML file, instead of passing them through to the API handlers.

This middleware takes care of the same Node.js server (Express.js app) at the same time and via the same URLs to serve both the application's JSON API endpoints and appliations assets needed for the browser to run the application.

Usage

For the middleware to run, it needs to be initialized with the proper parameters and prerequisites. It expects to receive an options object containing the following items

  • appShell - optional hash object containing options to render the application shell HTML. Supported fields are:
    • view - indicates the name of the view (template) to render (default: 'index')
    • layout - indicates whether view should be rendered in a master layout (default: false)
  • appConfig - required hash object with application configuration. Required fields:
    • appTitle - used to render the application shell HTML <title> tag
    • the whole object will be passed to the client-side through the app shell <script> tag
    • it can contain any additional config needed by the client-side app
  • appData - optional hash object with application bootstrap data
    • default: {}
    • the whole object will be passed to the client-side through the app shell <script> tag
    • it should contain any initial set of data for the client-side app
  • voidFilterRoutes - optional array of routes to void filtering on
    • default: []

Example of the middleware initialization and usage:

var express   = require('express')
  , ReqFilter = require('connect-spa-request-filter')
  , app       = express()
  , reqFilter;

reqFilter = ReqFilter.configure({
  appConfig       : { appTitle: 'My Super Single Page App' },
  appData         : {},
  appShell        : { view: 'index', layout: false },
  voidFilterRoutes: ['/logout']
});

// NOTE: use reqFilter **after** static middleware so it doesn't intercept static content serving
app.use(reqFilter());

History

  • 0.3.0 - [2014-04-14] Included rendering of the app shell within the middleware, with configurable options
  • 0.2.2 - [2014-04-14] Relaxing lodash version dependency
  • 0.2.1 - [2013-xx-xx] Unpublished. Because reasons.
  • 0.2.0 - [2013-05-09] Adding an option to void filtering on a defined set of routes
  • 0.1.0 - [2013-04-22] Initial release

License

This library is licensed under the MIT License