Skip to content

Commit

Permalink
Add [email protected] changes to express 5 migration guide
Browse files Browse the repository at this point in the history
closes #1114
  • Loading branch information
HarshithaKP authored and dougwilson committed Feb 15, 2022
1 parent 2fc9055 commit ef068f8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 25 deletions.
26 changes: 1 addition & 25 deletions _includes/api/en/5x/app-use.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,31 +97,7 @@ app.use('/abcd', function (req, res, next) {
This will match paths starting with `/abcd` and `/abd`:

```js
app.use('/abc?d', function (req, res, next) {
next()
})
```

This will match paths starting with `/abcd`, `/abbcd`, `/abbbbbcd`, and so on:

```js
app.use('/ab+cd', function (req, res, next) {
next()
})
```

This will match paths starting with `/abcd`, `/abxcd`, `/abFOOcd`, `/abbArcd`, and so on:

```js
app.use('/ab*cd', function (req, res, next) {
next()
})
```

This will match paths starting with `/ad` and `/abcd`:

```js
app.use('/a(bc)?d', function (req, res, next) {
app.use('/ab(c?)d', function (req, res, next) {
next()
})
```
Expand Down
15 changes: 15 additions & 0 deletions en/guide/migrating-5.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ See the [pull request](https://github.com/expressjs/express/pull/2237) for a lis
**Changed**

<ul class="doclist">
<li><a href="#path-syntax">Path route matching syntax</a></li>
<li><a href="#app.router">app.router</a></li>
<li><a href="#req.host">req.host</a></li>
<li><a href="#req.query">req.query</a></li>
Expand Down Expand Up @@ -112,6 +113,20 @@ The `res.sendfile()` function has been replaced by a camel-cased version `res.se

<h3>Changed</h3>

<h4 id="path-syntax">Path route matching syntax</h4>

Path route matching syntax is when a string is supplied as the first parameter to the `app.all()`, `app.use()`, `app.METHOD()`, `router.all()`, `router.METHOD()`, and `router.use()` APIs. The following changes have been made to how the path string is matched to an incoming request:

- Add new `?`, `*`, and `+` parameter modifiers.
- Matching group expressions are only RegExp syntax.
* `(*)` is no longer valid and must be written as `(.*)`, for example.
- Named matching groups no longer available by position in `req.params`.
* `/:foo(.*)` only captures as `req.params.foo` and not available as `req.params[0]`.
- Regular expressions can only be used in a matching group.
* `/\\d+` is no longer valid and must be written as `/(\\d+)`.
- Special `*` path segment behavior removed.
* `/foo/*/bar` will match a literal `*` as the middle segment.

<h4 id="app.router">app.router</h4>

The `app.router` object, which was removed in Express 4, has made a comeback in Express 5. In the new version, this object is a just a reference to the base Express router, unlike in Express 3, where an app had to explicitly load it.
Expand Down

0 comments on commit ef068f8

Please sign in to comment.