From ad6dd6ab90daefc6c69d9f85ea20cabaabd28923 Mon Sep 17 00:00:00 2001 From: Sebastian Beltran Date: Wed, 11 Sep 2024 19:55:13 -0500 Subject: [PATCH 1/8] add res.query and res.redirect --- en/guide/migrating-5.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/en/guide/migrating-5.md b/en/guide/migrating-5.md index 377697d97..6b03f9863 100755 --- a/en/guide/migrating-5.md +++ b/en/guide/migrating-5.md @@ -31,6 +31,7 @@ You can then run your automated tests to see what fails, and fix problems accord
  • req.param(name)
  • res.json(obj, status)
  • res.jsonp(obj, status)
  • +
  • res.redirect(url, status)
  • res.send(body, status)
  • res.send(status)
  • res.sendfile()
  • @@ -44,6 +45,7 @@ You can then run your automated tests to see what fails, and fix problems accord
  • app.router
  • req.host
  • req.query
  • +
  • res.vary
  • **Improvements** @@ -94,6 +96,10 @@ Express 5 no longer supports the signature `res.json(obj, status)`. Instead, set Express 5 no longer supports the signature `res.jsonp(obj, status)`. Instead, set the status and then chain it to the `res.jsonp()` method like this: `res.status(status).jsonp(obj)`. +

    res.redirect(url, status)

    + +Express 5 no longer supports the signature `res.redirect(url, status)`. Instead, use the following signature: `res.redirect(status, url)`. +

    res.send(body, status)

    Express 5 no longer supports the signature `res.send(obj, status)`. Instead, set the status and then chain it to the `res.send()` method like this: `res.status(status).send(obj)`. @@ -141,6 +147,10 @@ In Express 4, the `req.host` function incorrectly stripped off the port number i The `req.query` property is no longer a writable property and is instead a getter. The default query parser has been changed from "extended" to "simple". +

    res.vary

    + +The `res.vary` throws an error when the `field` argument is missing. In Express 4, if the argument was omitted, it gave a warning in the console +

    Improvements

    res.render()

    From cd7eace1741891f3f23384e2b4b8650fed2f5909 Mon Sep 17 00:00:00 2001 From: Sebastian Beltran Date: Thu, 12 Sep 2024 19:18:18 -0500 Subject: [PATCH 2/8] add express.urlencoded and req.body --- en/guide/migrating-5.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/en/guide/migrating-5.md b/en/guide/migrating-5.md index 6b03f9863..40fb54889 100755 --- a/en/guide/migrating-5.md +++ b/en/guide/migrating-5.md @@ -42,7 +42,9 @@ You can then run your automated tests to see what fails, and fix problems accord @@ -157,6 +159,14 @@ In Express 4, the `req.host` function incorrectly stripped off the port number i The `req.query` property is no longer a writable property and is instead a getter. The default query parser has been changed from "extended" to "simple". +

    res.clearCookie

    + +The `res.clearCookie` method ignores the `maxAge` and `expires` options provided by the user. + +

    res.status

    + +The `res.status` method only accepts integers in the range of `100` to `999`, following the behavior defined by Node.js, and it returns an error when the status code is not an integer. +

    res.vary

    The `res.vary` throws an error when the `field` argument is missing. In Express 4, if the argument was omitted, it gave a warning in the console From 637051e2f8d656edb84a306a152ae696de682bce Mon Sep 17 00:00:00 2001 From: Sebastian Beltran Date: Fri, 13 Sep 2024 18:37:16 -0500 Subject: [PATCH 4/8] update introduction page --- en/guide/migrating-5.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/en/guide/migrating-5.md b/en/guide/migrating-5.md index e2d021618..55c6b527f 100755 --- a/en/guide/migrating-5.md +++ b/en/guide/migrating-5.md @@ -9,9 +9,9 @@ redirect_from: "/guide/migrating-5.html"

    Overview

    -Express 5.0 is still in the beta release stage, but here is a preview of the changes that will be in the release and how to migrate your Express 4 app to Express 5. +Express 5 is not very different from Express 4; although it maintains the same basic API, there are still changes that break compatibility with the previous version. Therefore, an application built with Express 4 might not work if you update it to use Express 5. -To install the latest beta and to preview Express 5, enter the following command in your application root directory: +To install this version, you need to have a Node.js version 18 or higher. Then, execute the following command in your application directory: ```console $ npm install "express@>={{ site.data.express.next_version }}" --save From 2e9de0def81c50afe5a03db506429ac81c2c67a5 Mon Sep 17 00:00:00 2001 From: Sebastian Beltran Date: Fri, 13 Sep 2024 20:17:23 -0500 Subject: [PATCH 5/8] add res.redirect('back') and res.location('back') --- en/guide/migrating-5.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/en/guide/migrating-5.md b/en/guide/migrating-5.md index 55c6b527f..c4fdd75e0 100755 --- a/en/guide/migrating-5.md +++ b/en/guide/migrating-5.md @@ -31,6 +31,7 @@ You can then run your automated tests to see what fails, and fix problems accord
  • req.param(name)
  • res.json(obj, status)
  • res.jsonp(obj, status)
  • +
  • res.redirect('back') and res.location('back')
  • res.redirect(url, status)
  • res.send(body, status)
  • res.send(status)
  • @@ -47,8 +48,8 @@ You can then run your automated tests to see what fails, and fix problems accord
  • req.body
  • req.host
  • req.query
  • -
  • res.status
  • res.clearCookie
  • +
  • res.status
  • res.vary
  • @@ -104,6 +105,11 @@ Express 5 no longer supports the signature `res.jsonp(obj, status)`. Instead, se Express 5 no longer supports the signature `res.redirect(url, status)`. Instead, use the following signature: `res.redirect(status, url)`. + +

    res.redirect('back') and res.location('back')

    + +Express 5 no longer supports the magic string `back` in the `res.redirect()` and `res.location()` methods. Instead, use the `req.get('Referrer') || '/'` value to redirect back to the previous page. In Express 4, the res.`redirect('back')` and `res.location('back')` methods were deprecated. +

    res.send(body, status)

    Express 5 no longer supports the signature `res.send(obj, status)`. Instead, set the status and then chain it to the `res.send()` method like this: `res.status(status).send(obj)`. From 7cdb0e56f43132170ccf2b002fce79cf09be1dad Mon Sep 17 00:00:00 2001 From: Sebastian Beltran Date: Fri, 13 Sep 2024 20:44:15 -0500 Subject: [PATCH 6/8] bring changes from #1317 --- en/guide/migrating-5.md | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/en/guide/migrating-5.md b/en/guide/migrating-5.md index c4fdd75e0..537c2fffb 100755 --- a/en/guide/migrating-5.md +++ b/en/guide/migrating-5.md @@ -129,15 +129,14 @@ The `res.sendfile()` function has been replaced by a camel-cased version `res.se 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. +- Add new `?`, `*`, and `+` parameter modifiers. For example `/users/:user+` now matches `/users/1`, `/users/1/2`, etc. but not `/users`. +- The special `*` path segment behavior has been removed. This means that `*` is no longer a valid path and `/foo/*/bar` now matches a literal `'*'`. For the previous behaviour, a `(.*)` matching group should be used instead. +- Named matching groups no longer available by position in `req.params`. For example, `/:foo(.*)` only captures as `req.params.foo` and not available as `req.params[0]`. +- Regular expressions can now only be used in a matching group. For example, `/users/\\d+` is invalid and should be written as `/users/(\\d+))`. +- It is now possible to use named capturing groups in paths using `RegExp`, for example `/\/(?.+)/` would result in `req.params.group` being populated. +- Custom prefix and suffix groups are now supported using `{}`, for example `/:entity{-:action}?` would match `/user` and `/user-delete`. +- Unbalanced patterns now produce an error. For example `/test(foo` previously worked, but now the opening parenthesis `(` must be escaped to match the previous behavior: `/test\\(foo`. +- As with parentheses, curly brackets also require escaping. That is, `/user{:id}` no longer matches `/user{42}` as before unless written as `/user\\{:id\\}`.

    Rejected promises handled from middleware and handlers

    From 49ad2e81e38a86225aca8fa9561dc7c79b4c412b Mon Sep 17 00:00:00 2001 From: Sebastian Beltran Date: Sat, 14 Sep 2024 13:37:41 -0500 Subject: [PATCH 7/8] add brotli support --- en/guide/migrating-5.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/en/guide/migrating-5.md b/en/guide/migrating-5.md index 537c2fffb..0318be4d2 100755 --- a/en/guide/migrating-5.md +++ b/en/guide/migrating-5.md @@ -57,6 +57,7 @@ You can then run your automated tests to see what fails, and fix problems accord

    Removed methods and properties

    @@ -181,3 +182,7 @@ The `res.vary` throws an error when the `field` argument is missing. In Express

    res.render()

    This method now enforces asynchronous behavior for all view engines, avoiding bugs caused by view engines that had a synchronous implementation and that violated the recommended interface. + +

    Brotli encoding support

    + +Express 5 supports Brotli encoding for requests.. \ No newline at end of file From 5fd7a0d4bfb7dc6251df09b22f326c8fe048c0a8 Mon Sep 17 00:00:00 2001 From: Sebastian Beltran Date: Tue, 17 Sep 2024 17:34:08 -0500 Subject: [PATCH 8/8] adapt router matching sintax --- en/guide/migrating-5.md | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/en/guide/migrating-5.md b/en/guide/migrating-5.md index 0318be4d2..969e7417e 100755 --- a/en/guide/migrating-5.md +++ b/en/guide/migrating-5.md @@ -117,7 +117,7 @@ Express 5 no longer supports the signature `res.send(obj, status)`. Instead, set

    res.send(status)

    -Express 5 no longer supports the signature res.send(status), where _`status`_ is a number. Instead, use the `res.sendStatus(statusCode)` function, which sets the HTTP response header status code and sends the text version of the code: "Not Found", "Internal Server Error", and so on. +Express 5 no longer supports the signature `res.send(status)`, where `status` is a number. Instead, use the `res.sendStatus(statusCode)` function, which sets the HTTP response header status code and sends the text version of the code: "Not Found", "Internal Server Error", and so on. If you need to send a number by using the `res.send()` function, quote the number to convert it to a string, so that Express does not interpret it as an attempt to use the unsupported old signature.

    res.sendfile()

    @@ -130,14 +130,23 @@ The `res.sendfile()` function has been replaced by a camel-cased version `res.se 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. For example `/users/:user+` now matches `/users/1`, `/users/1/2`, etc. but not `/users`. -- The special `*` path segment behavior has been removed. This means that `*` is no longer a valid path and `/foo/*/bar` now matches a literal `'*'`. For the previous behaviour, a `(.*)` matching group should be used instead. -- Named matching groups no longer available by position in `req.params`. For example, `/:foo(.*)` only captures as `req.params.foo` and not available as `req.params[0]`. -- Regular expressions can now only be used in a matching group. For example, `/users/\\d+` is invalid and should be written as `/users/(\\d+))`. -- It is now possible to use named capturing groups in paths using `RegExp`, for example `/\/(?.+)/` would result in `req.params.group` being populated. -- Custom prefix and suffix groups are now supported using `{}`, for example `/:entity{-:action}?` would match `/user` and `/user-delete`. -- Unbalanced patterns now produce an error. For example `/test(foo` previously worked, but now the opening parenthesis `(` must be escaped to match the previous behavior: `/test\\(foo`. -- As with parentheses, curly brackets also require escaping. That is, `/user{:id}` no longer matches `/user{42}` as before unless written as `/user\\{:id\\}`. +- The wildcard `*` must have a name, matching the behavior of parameters `:`, use `/*splat` instead of `/*` +- The optional character `?` is no longer supported, use braces instead: `/:file{.:ext}`. +- Regexp characters are not supported. For example: +```js +app.get('/[discussion|page]/:slug', async (req, res) => { + res.status(200).send('ok') +}) +``` +should be changed to: +```js +app.get(['/discussion/:slug', '/page/:slug'], async (req, res) => { + res.status(200).send('ok') +}) +``` + +- Some characters have been reserved to avoid confusion during upgrade (`()[]?+!`), use `\` to escape them. +- Parameter names now support valid JavaScript identifiers, or quoted like `:"this"`.

    Rejected promises handled from middleware and handlers

    @@ -185,4 +194,4 @@ This method now enforces asynchronous behavior for all view engines, avoiding bu

    Brotli encoding support

    -Express 5 supports Brotli encoding for requests.. \ No newline at end of file +Express 5 supports Brotli encoding for requests received from clients that support it. \ No newline at end of file