Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/schamberg97/express-normalizeurl
Fork of unmaintained @AntuanKhanna/express-url, which fixes some of the issues of the former
https://github.com/schamberg97/express-normalizeurl
Last synced: 8 days ago
JSON representation
Fork of unmaintained @AntuanKhanna/express-url, which fixes some of the issues of the former
- Host: GitHub
- URL: https://github.com/schamberg97/express-normalizeurl
- Owner: schamberg97
- License: other
- Created: 2019-07-11T13:18:18.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-07-12T18:01:49.000Z (over 4 years ago)
- Last Synced: 2024-04-25T22:21:44.560Z (7 months ago)
- Language: JavaScript
- Size: 52.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Express-NormalizeUrl
URL normalisation for Express and Connect. Forked from deleted [@AntuanKhanna/express-url](https://github.com/AntuanKhanna/express-url) to serve as an (almost) drop-in replacement (please see Middleware options for that matter) for an unmaintained project.## About
### Taking care of
* trailing slashes
* repeated slashes
* repeated question marks
* repeated ampersands
* repeated query strings
* case sensitivity (does not affect queries by default)### Redirect example
```
//assuming default options (see Middleware options)
request: //sLuG??param=val&¶m2=VAL2
response: /slug/?param=val¶m2=VAL2
```## Installation
```sh
$ npm install express-normalizeurl
```## Usage
### As middleware
```js
// Require module
// If you used express-url before, this is the only line you need to change
var expurl = require('express-normalizeurl');// Process routes through middleware
app.use(expurl());
```### Middleware options
```js
app.use(expurl({
requestType: 'GET',
redirectStatusCode: 302,
lowercase: true,
lowercaseQueries: false, // False by default, requires lowercase to be set to true to work. If you want 100% compatibility with express-url, when lowercase is true, this also needs to be set true
trailingSlash: true,
repeatedSlash: true,
repeatedQuestionMark: true,
repeatedAmpersand: true
}));
```## Tests
```sh
$ npm install
$ cd node_modules/express-normalizeurl
$ npm test
```## Recommendations
* do not serve static files with node directly
* use case sensitive and strict routing```js
app.set('case sensitive routing', true);
app.set('strict routing', true);
```