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

v1.2.2

Published

Flexible redirection plugin

Downloads

4,734

Readme

express-redirect Build Status NPM Version

express-redirect offers you simple and blazing fast redirection rules. Even very complex redirect rules don't take longer than 1 ms. It just comes down to concatenating strings.

Say goodbye to writing 10 lines of code for a plain redirection over and over again.

If you want redirections with fancy JS expressions, you should probably check out deviate.

Deprecation Notice

This package isn't actively maintained anymore. It was written for express v3.x, but still seems to work with express v4.x. Use it at your own risk.

If you want to continue this project, ping me and I'll add you as an owner on npm.

Installation

$ npm install express-redirect
var express = require("express")
  , redirect = require("express-redirect");

var app = express();
redirect(app); // mount the plugin

Example

// just a smple redirect
app.redirect("/p/:id", "/page/:id");

// you want it permanent?
app.redirect("/p/:id", "/page/:id", 301);

// if you want to append the query string (?foo=bar)
app.redirect("/p/:id", "/page/:id", 301, true);

// no id, goto page # 1
app.redirect("/p/:id?", "/page/:id(1)");

// only redirect POST (for whatever reason)
app.redirect("/contact", "/thanks", "post")

// a bit more complex
app.redirect(
  "/entry/:entry/comments/:action(view|edit|delete)?/:id([0-9]+)/:reply([0-9]+)?",
  "/entry/:entry/comments/:action(view)/:id/:reply?"
);

// external redirects work too
app.redirect(
  "/google/:query?",
  "https://www.google.de/?q=:query(Nyan+Cat)"
);

API

express-redirect mounts the new method app.redirect(route, target, [status], [method], [qsa]) to your app. You can access it just like app.get() or app.post() etc.

route

The parameter route is a string and is required. It can contain parameters like :id, :year([0-9]{4})? or :action(view|edit). It's basically just the same as a route you would pass to app.get().

target

The parameter target is a string and is required. It can contain parameters like :id, :year? or :action(view), where a ? marks an optional parameter and (someString) is a default value.
The parameters get replaced by their respective counterparts in the route.

app.redirect("/a/:id([0-9]+)?", "/b/:id(1)");
app.redirect("/c/:action(view|delete)?", "/d/:action?");
/a           -> /b/1
/a/100       -> /b/100
/c           -> /d
/c/view      -> /d/view

status

The parameter status is an integer and is optional. It is a HTTP (redirection) status code. It defaults to 307 (Temporary Redirect).

method

The parameter method is a string and is optional. It is a VERB as in express' router. It defaults to all.

qsa

The parameter qsa is a boolean and is optional. It defaults to false. If set to true, the query string will be appended. By default, it will be discarded.

License

(The MIT License)

Copyright (c) 20012-2013 Jan Buschtöns <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.