Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

express-redirect

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-redirect - npm Package Compare versions

Comparing version 1.1.1 to 1.2.0

0

lib/compile.js

@@ -0,0 +0,0 @@ // module dependencies

@@ -0,0 +0,0 @@ // expose parser

@@ -0,0 +0,0 @@ // module dependencies

23

lib/redirect.js

@@ -16,9 +16,19 @@ // module dependencies

// append the query string, if it exists
function appendQueryString(compiled, req) {
var queryPos = req.url.indexOf("?");
return ~queryPos
? compiled + req.url.substr(queryPos)
: compiled;
}
// app.redirect(route, target, status)
function redirect(route, target, status, method, check) {
var args = sanitize(arguments, redirect, [[String, RegExp], ["/"], [302], ["all"], [Function, false]])
function redirect(route, target, status, method, qsa, check) {
var args = sanitize(arguments, redirect, [[String, RegExp], ["/"], [302], ["all"], [false], [Function, false]])
, status = args.status
, method = args.method.toLowerCase()
, target = precompile(parsePath(args.route), parsePath(args.target))
, check = args.check;
, check = args.check
, qsa = args.qsa;

@@ -29,2 +39,3 @@ // register route

var compiled = compile(req.params, target);
if(qsa) compiled = appendQueryString(compiled, req);

@@ -36,5 +47,7 @@ if(compiled != req.url) res.redirect(status, compiled);

this[method](route, function(req, res, next) {
var compiled = compile(req.params, target)
, result = check(route, compiled, req, res);
var compiled = compile(req.params, target);
if(qsa) compiled = appendQueryString(compiled, req);
var result = check(route, compiled, req, res);
if(result === false) return next();

@@ -41,0 +54,0 @@ else if(typeof result == "string") res.redirect(status, result);

{
"name": "express-redirect",
"description": "Flexible redirection plugin",
"version": "1.1.1",
"version": "1.2.0",
"author": "Jan Buschtöns <buschtoens@gmail.com>",

@@ -10,3 +10,3 @@ "contributors": [

"email": "buschtoens@gmail.com",
"url": "https://github.com/silvinci"
"url": "https://github.com/buschtoens"
}

@@ -25,3 +25,3 @@ ],

],
"repository": "git://github.com/silvinci/express-redirect",
"repository": "git://github.com/buschtoen/express-redirect",
"main": "index",

@@ -28,0 +28,0 @@ "engines": {

@@ -32,2 +32,5 @@ # express-redirect [![Build Status](https://img.shields.io/travis/phvcky/express-redirect.svg?branch=master)](https://travis-ci.org/phvcky/express-redirect) [![NPM Version](https://img.shields.io/npm/v/express-redirect.svg)](https://www.npmjs.org/package/express-redirect)

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

@@ -53,3 +56,3 @@ app.redirect("/p/:id?", "/page/:id(1)");

## API
express-redirect mounts the new method `app.redirect(route, target, [status], [method])` to your app.
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.

@@ -89,3 +92,7 @@

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

@@ -92,0 +99,0 @@

@@ -0,0 +0,0 @@ // get the lib

[
]

@@ -0,0 +0,0 @@ // get the lib

@@ -0,0 +0,0 @@ // get the lib

@@ -0,0 +0,0 @@ // get the lib and express

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc