1.2.1 • Published 8 years ago

normy v1.2.1

Weekly downloads
10
License
MIT
Repository
github
Last release
8 years ago

Normy

Normy is a URL normalization middleware for Express. The package will allow you to configure normalization rules and then universally redirect any GET request that doesn't follow the rules.

Build Status

Install

npm install --save normy

Usage

    const app = require('express');
    const normy = require('normy');
    
    const options = {
      forceProtocol: 'none',
      forceWww: 'www',
      forceTrailingSlash: 'trim',
      forceCase: 'lower',
      forceCaseQuery: 'none',
      redirectType: '301',
      excludedPaths: ['/MyPath', '/MySecondPath', '^MyRegEx'],
    }
    
    // Middleware for all GET routes
    app.get('*', normy(options));

Options

OptionRequiredValid ValuesDefaultDescription
forceProtocolnohttp, https, nonenoneForce redirect to protocol
forceWwwnowww, no-www, nonewwwForce host name to keep or remove www
forceTrailingSlashnotrim, keep, nonetrimForce path to trim or keep trailing forward slash
forceCasenolower, upper, nonelowerForce URL protocol, host name and path to lower or upper case
forceCaseQuerynolower, upper, nonenoneForce query string to lower or upper case. Use with caution
redirectTypeno301, 302301Redirect type if requesting URL needs it
excludedPathsnostring1, string2..[]Exclude paths from normalization rules. Array of RegEx strings

Test

npm test