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-ua-redirect

v1.0.4

Published

Express UA Redirect is a simple configurable middleware for ExpressJS allowing you to redirect all routes to a configured route based on user agent restrictions.

Downloads

133

Readme

Express User Agent Redirect

Coverage Status

Express UA Redirect is a simple configurable middleware for ExpressJS allowing you to redirect all routes to a configured route based on user agent restrictions. It was create to warn the user that the browser is not compatible, but it can be used for other reasons.

Here is an example to redirect IE 8 and less user to /incompatible-browser route:

app.use(uaRedirect({
  browsers: {
    unauthorized: {
      IE: '8-'
    }
  },
  redirectTo: '/incompatible-browser'
}));

There is also an evergreen mode to accept all automatic updated browsers and redirect all other:

app.use(uaRedirect({
  browsers: {
    evergreen: true
  },
  redirectTo: '/incompatible-browser'
}));

Installation

Install the dependency

npm install --save express-ua-redirect

Install it on your express server

var uaRedirect = require('express-ua-redirect');
//...
app.use(uaRedirect(options));

How to use

  1. Proceed to installation has describe before
  2. Configure the browsers option
  3. Add a route to your server according to the option redirectTo
  4. Make what you will with this route
  5. You're done!

Exemple

To redirect IE7 to /update-your-browser who it render update-your-browser.ejs template.

server.js

var express = require('express');
var uaRedirect = require('express-ua-redirect');

var app = express();
app.set('view engine', 'ejs');

// Configure uaRedirect
app.use(uaRedirect({
  browsers: {
    unauthorized: {
      IE: 7
    }
  },
  redirectTo: '/update-your-browser'
}));

// ...
// Define your routes
// ...

// Define the associate route to `redirectTo` option
app.get('/update-your-browser', function(req, res) {
  res.render('update-your-browser');
});

update-your-browser.ejs

<h1>Oups your browser is not compatible</h1>
<p>We recommend that you update your browser ...</p>

options

  • browsers {Object}
    • unauthorized {Object} Specify unauthorized browser(s) and its version with a browser object described below
    • authorized {Object} Specify authorized browser(s) and its version with a browser object described below
    • evergreen {Boolean} Redirect all not evergreen browser
  • redirectTo {String} Route path

Browser object possibilities

{
  IE: 8,         // match the exact version of IE8
  Chrome: '44+', // match chrome 44 and above
  Safari: '8-'   // match safari 8 and below
}

Browser name is not case sensitive an you can use all browser listed on ua-parser-js plugin documentation here

Version condition can be String or Number. With + or - indicator it must be a String.

Priority order

If you specify an unauthorized browser it will override authorized browser and authorized override evergreen browsers.

unauthorized > authorized > evergreen

Use cases

Lock IE8 and below

app.use(uaRedirect({
  browsers: {
    unauthorized: {
      IE: '8-'
    }
  },
  redirectTo: '/incompatible-browser'
}));

Authorized modern browsers

app.use(uaRedirect({
  browsers: {
    authorized: {
      safari: '7+',
      IE: '9+'
    },
    evergreen: true
  },
  redirectTo: '/incompatible-browser'
}));