An open API service indexing awesome lists of open source software.

https://github.com/foundy/express-resolve-path

Rewrite the path of the request url in the correct form.
https://github.com/foundy/express-resolve-path

express path pathname resolve

Last synced: 4 months ago
JSON representation

Rewrite the path of the request url in the correct form.

Awesome Lists containing this project

README

          

# express-resolve-path
[![Build Status](https://travis-ci.org/foundy/express-resolve-path.svg?branch=master)](https://travis-ci.org/foundy/express-resolve-path)

`Recommended Node.js version`: **>= 8.9.0 (LTS)**

Express middleware that rewrites paths with multiple slashes to the correct path.

For example, when a request comes in the path of multiple slashes, it is rewritten to the converted path as shown below to match the routing rule.

`Request path`: ///foo///bar//?val=hello

`Rewrite path`: /foo/bar?val=hello

# Install

`$ npm install express-resolve-path`

# API

```javascript
const resolvePath = require('express-resolve-path');

const app = express();

app.use(resolvePath());

app.get('/foo', (req, res) => res.send('Hello'));
```

## resolvePath([options])

### Options

#### methods
Specifies the requested method to apply. (not case-sensitive)

```javascript
// methods specifying a single method
app.use(resolvePath({ methods: 'GET' }));

// methods specify multiple methods
app.use(resolvePath({ methods: 'GET POST' }));

// methods
app.use(resolvePath({ methods: ['GET', 'POST'] }));
```

# License
[MIT](https://github.com/foundy/express-resolve-path/blob/master/LICENSE)