rsnext/errors/middleware-upgrade-guide.md

388 lines
12 KiB
Markdown
Raw Normal View History

Add upgrade guide for Middleware. (#37382) * Middleware upgrade guide * Add a bit more * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> Co-authored-by: Edward Thomson <ethomson@github.com> Co-authored-by: Dominik Ferber <dominik.ferber@gmail.com> * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> * Updates based on PR comments * Add before / after * Flip paragraphs * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> * Apply suggestions from code review Co-authored-by: Kiko Beats <josefrancisco.verdu@gmail.com> * Apply suggestions from code review * Apply suggestions from code review * Apply suggestions from code review Co-authored-by: Damien Simonin Feugas <damien.feugas@gmail.com> * Update errors/middleware-upgrade-guide.md Co-authored-by: Dom Sip <dominik.sipowicz@gmail.com> * Update errors/middleware-upgrade-guide.md Co-authored-by: Damien Simonin Feugas <damien.feugas@gmail.com> * Update middleware-upgrade-guide.md * Update errors/middleware-upgrade-guide.md Co-authored-by: Rich Haines <hello@richardhaines.dev> * Update errors/middleware-upgrade-guide.md Co-authored-by: Rich Haines <hello@richardhaines.dev> * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> * Apply suggestions from code review * Update errors/middleware-upgrade-guide.md Co-authored-by: Rich Haines <hello@richardhaines.dev> Co-authored-by: Edward Thomson <ethomson@github.com> Co-authored-by: Dominik Ferber <dominik.ferber@gmail.com> Co-authored-by: Kiko Beats <josefrancisco.verdu@gmail.com> Co-authored-by: Damien Simonin Feugas <damien.feugas@gmail.com> Co-authored-by: Dom Sip <dominik.sipowicz@gmail.com>
2022-06-16 18:29:18 +02:00
# Middleware Upgrade Guide
As we work on improving Middleware for General Availability (GA), we've made some changes to the Middleware APIs (and how you define Middleware in your application) based on your feedback.
This upgrade guide will help you understand the changes and how to migrate your existing Middleware to the new API. The guide is for Next.js developers who:
- Currently use the beta Next.js Middleware features
- Choose to upgrade to the next stable version of Next.js (`v12.2`)
You can start upgrading your Middleware usage today with the latest canary release (`npm i next@canary`).
If you have ESLint configured, you will need to run `npm i eslint-config-next@canary --save-dev` to upgrade your ESLint configuration to ensure the same version is being used as the Next.js version. You might also need to restart VSCode for the changes to take effect.
Add upgrade guide for Middleware. (#37382) * Middleware upgrade guide * Add a bit more * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> Co-authored-by: Edward Thomson <ethomson@github.com> Co-authored-by: Dominik Ferber <dominik.ferber@gmail.com> * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> * Updates based on PR comments * Add before / after * Flip paragraphs * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> * Apply suggestions from code review Co-authored-by: Kiko Beats <josefrancisco.verdu@gmail.com> * Apply suggestions from code review * Apply suggestions from code review * Apply suggestions from code review Co-authored-by: Damien Simonin Feugas <damien.feugas@gmail.com> * Update errors/middleware-upgrade-guide.md Co-authored-by: Dom Sip <dominik.sipowicz@gmail.com> * Update errors/middleware-upgrade-guide.md Co-authored-by: Damien Simonin Feugas <damien.feugas@gmail.com> * Update middleware-upgrade-guide.md * Update errors/middleware-upgrade-guide.md Co-authored-by: Rich Haines <hello@richardhaines.dev> * Update errors/middleware-upgrade-guide.md Co-authored-by: Rich Haines <hello@richardhaines.dev> * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> * Apply suggestions from code review * Update errors/middleware-upgrade-guide.md Co-authored-by: Rich Haines <hello@richardhaines.dev> Co-authored-by: Edward Thomson <ethomson@github.com> Co-authored-by: Dominik Ferber <dominik.ferber@gmail.com> Co-authored-by: Kiko Beats <josefrancisco.verdu@gmail.com> Co-authored-by: Damien Simonin Feugas <damien.feugas@gmail.com> Co-authored-by: Dom Sip <dominik.sipowicz@gmail.com>
2022-06-16 18:29:18 +02:00
## Using Next.js Middleware on Vercel
If you're using Next.js on Vercel, your existing deploys using Middleware will continue to work, and you can continue to deploy your site using Middleware. When you upgrade your site to the next stable version of Next.js (`v12.2`), you will need to follow this upgrade guide to update your Middleware.
## Breaking changes
1. [No Nested Middleware](#no-nested-middleware)
2. [No Response Body](#no-response-body)
3. [Cookies API Revamped](#cookies-api-revamped)
4. [New User-Agent Helper](#new-user-agent-helper)
5. [No More Page Match Data](#no-more-page-match-data)
6. [Executing Middleware on Internal Next.js Requests](#executing-middleware-on-internal-nextjs-requests)
## No Nested Middleware
### Summary of changes
- Define a single Middleware file next to your `pages` folder
Add upgrade guide for Middleware. (#37382) * Middleware upgrade guide * Add a bit more * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> Co-authored-by: Edward Thomson <ethomson@github.com> Co-authored-by: Dominik Ferber <dominik.ferber@gmail.com> * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> * Updates based on PR comments * Add before / after * Flip paragraphs * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> * Apply suggestions from code review Co-authored-by: Kiko Beats <josefrancisco.verdu@gmail.com> * Apply suggestions from code review * Apply suggestions from code review * Apply suggestions from code review Co-authored-by: Damien Simonin Feugas <damien.feugas@gmail.com> * Update errors/middleware-upgrade-guide.md Co-authored-by: Dom Sip <dominik.sipowicz@gmail.com> * Update errors/middleware-upgrade-guide.md Co-authored-by: Damien Simonin Feugas <damien.feugas@gmail.com> * Update middleware-upgrade-guide.md * Update errors/middleware-upgrade-guide.md Co-authored-by: Rich Haines <hello@richardhaines.dev> * Update errors/middleware-upgrade-guide.md Co-authored-by: Rich Haines <hello@richardhaines.dev> * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> * Apply suggestions from code review * Update errors/middleware-upgrade-guide.md Co-authored-by: Rich Haines <hello@richardhaines.dev> Co-authored-by: Edward Thomson <ethomson@github.com> Co-authored-by: Dominik Ferber <dominik.ferber@gmail.com> Co-authored-by: Kiko Beats <josefrancisco.verdu@gmail.com> Co-authored-by: Damien Simonin Feugas <damien.feugas@gmail.com> Co-authored-by: Dom Sip <dominik.sipowicz@gmail.com>
2022-06-16 18:29:18 +02:00
- No need to prefix the file with an underscore
- A custom matcher can be used to define matching routes using an exported config object
### Explanation
Previously, you could create a `_middleware.ts` file under the `pages` directory at any level. Middleware execution was based on the file path where it was created. Beta customers found this route matching confusing. For example:
- Middleware in `pages/dashboard/_middleware.ts`
- Middleware in `pages/dashboard/users/_middleware.ts`
- A request to `/dashboard/users/*` **would match both.**
Based on customer feedback, we have replaced this API with a single root Middleware.
### How to upgrade
You should declare **one single Middleware file** in your application, which should be located next to the `pages` directory and named **without** an `_` prefix. Your Middleware file can still have either a `.ts` or `.js` extension.
Add upgrade guide for Middleware. (#37382) * Middleware upgrade guide * Add a bit more * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> Co-authored-by: Edward Thomson <ethomson@github.com> Co-authored-by: Dominik Ferber <dominik.ferber@gmail.com> * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> * Updates based on PR comments * Add before / after * Flip paragraphs * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> * Apply suggestions from code review Co-authored-by: Kiko Beats <josefrancisco.verdu@gmail.com> * Apply suggestions from code review * Apply suggestions from code review * Apply suggestions from code review Co-authored-by: Damien Simonin Feugas <damien.feugas@gmail.com> * Update errors/middleware-upgrade-guide.md Co-authored-by: Dom Sip <dominik.sipowicz@gmail.com> * Update errors/middleware-upgrade-guide.md Co-authored-by: Damien Simonin Feugas <damien.feugas@gmail.com> * Update middleware-upgrade-guide.md * Update errors/middleware-upgrade-guide.md Co-authored-by: Rich Haines <hello@richardhaines.dev> * Update errors/middleware-upgrade-guide.md Co-authored-by: Rich Haines <hello@richardhaines.dev> * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> * Apply suggestions from code review * Update errors/middleware-upgrade-guide.md Co-authored-by: Rich Haines <hello@richardhaines.dev> Co-authored-by: Edward Thomson <ethomson@github.com> Co-authored-by: Dominik Ferber <dominik.ferber@gmail.com> Co-authored-by: Kiko Beats <josefrancisco.verdu@gmail.com> Co-authored-by: Damien Simonin Feugas <damien.feugas@gmail.com> Co-authored-by: Dom Sip <dominik.sipowicz@gmail.com>
2022-06-16 18:29:18 +02:00
Middleware will be invoked for **every route in the app**, and a custom matcher can be used to define matching filters. The following is an example for a Middleware that triggers for `/about/*` and `/dashboard/:path*`, the custom matcher is defined in an exported config object:
```typescript
// middleware.ts
import { NextResponse } from 'next/server'
import type { NextRequest } from 'next/server'
export function middleware(request: NextRequest) {
return NextResponse.rewrite(new URL('/about-2', request.url))
}
// Supports both a single string value or an array of matchers
export const config = {
matcher: ['/about/:path*', '/dashboard/:path*'],
}
```
While the config option is preferred since it doesn't get invoked on every request, you can also use conditional statements to only run the Middleware when it matches specific paths. One advantage of using conditionals is defining explicit ordering for when Middleware executes. The following example shows how you can merge two previously nested Middleware:
```typescript
// <root>/middleware.js
import type { NextRequest } from 'next/server'
export function middleware(request: NextRequest) {
if (request.nextUrl.pathname.startsWith('/about')) {
// This logic is only applied to /about
}
if (request.nextUrl.pathname.startsWith('/dashboard')) {
// This logic is only applied to /dashboard
}
}
```
## No Response Body
### Summary of changes
Middleware docs update (#38111) * Initial outline added for middleware docs * Feedback changes - not included new user agent yet * edge api routes docs * middleware page some cleanup * moved api stuff to next server, added useragent * waitUntil example added * Updated env vars section * Added cookies on the request object example * fixed naming * fixed import typo * Amy feedback * Update docs/advanced-features/middleware.md Co-authored-by: Amy Burns <amy.burns@vercel.com> * first commit * more fixes * re-structuring based on feedback * changes to middleware.md * updates to edge-api-routes * code typo * Update docs/advanced-features/middleware.md Co-authored-by: JJ Kasper <jj@jjsweb.site> * Update edge-api-routes.md * Update Edge Runtime API docs * Clarify API docs * Update * Update docs/advanced-features/middleware.md * Update switchable runtime docs * Update response * experimental-edge * Update docs/advanced-features/middleware.md * Add example of forwarding headers and address comments * Add proxying headers to middleware upgrade guide * Apply suggestions from code review Co-authored-by: Jeff Escalante <jescalan@users.noreply.github.com> * fix middleware directory spec * localization explanation * update detecting runtime * Update docs/advanced-features/react-18/switchable-runtime.md Co-authored-by: Balázs Orbán <info@balazsorban.com> * fix prettier issues * table fix * Update docs/advanced-features/react-18/switchable-runtime.md Co-authored-by: Jeff Escalante <jescalan@users.noreply.github.com> * Update docs/api-routes/edge-api-routes.md Co-authored-by: Jeff Escalante <jescalan@users.noreply.github.com> * lint-fix Co-authored-by: molebox <hello@richardhaines.dev> Co-authored-by: Amy Burns <amy.burns@vercel.com> Co-authored-by: Ismael Rumzan <ismael.rumzan@gmail.com> Co-authored-by: Lee Robinson <me@leerob.io> Co-authored-by: Balázs Orbán <info@balazsorban.com> Co-authored-by: Jeff Escalante <jescalan@users.noreply.github.com> Co-authored-by: Ismael <ismael@vercel.com>
2022-06-28 17:22:48 +02:00
- Middleware can no longer produce a response body
Add upgrade guide for Middleware. (#37382) * Middleware upgrade guide * Add a bit more * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> Co-authored-by: Edward Thomson <ethomson@github.com> Co-authored-by: Dominik Ferber <dominik.ferber@gmail.com> * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> * Updates based on PR comments * Add before / after * Flip paragraphs * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> * Apply suggestions from code review Co-authored-by: Kiko Beats <josefrancisco.verdu@gmail.com> * Apply suggestions from code review * Apply suggestions from code review * Apply suggestions from code review Co-authored-by: Damien Simonin Feugas <damien.feugas@gmail.com> * Update errors/middleware-upgrade-guide.md Co-authored-by: Dom Sip <dominik.sipowicz@gmail.com> * Update errors/middleware-upgrade-guide.md Co-authored-by: Damien Simonin Feugas <damien.feugas@gmail.com> * Update middleware-upgrade-guide.md * Update errors/middleware-upgrade-guide.md Co-authored-by: Rich Haines <hello@richardhaines.dev> * Update errors/middleware-upgrade-guide.md Co-authored-by: Rich Haines <hello@richardhaines.dev> * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> * Apply suggestions from code review * Update errors/middleware-upgrade-guide.md Co-authored-by: Rich Haines <hello@richardhaines.dev> Co-authored-by: Edward Thomson <ethomson@github.com> Co-authored-by: Dominik Ferber <dominik.ferber@gmail.com> Co-authored-by: Kiko Beats <josefrancisco.verdu@gmail.com> Co-authored-by: Damien Simonin Feugas <damien.feugas@gmail.com> Co-authored-by: Dom Sip <dominik.sipowicz@gmail.com>
2022-06-16 18:29:18 +02:00
- If your Middleware _does_ respond with a body, a runtime error will be thrown
- Migrate to using `rewrite`/`redirect` to pages/APIs handling a response
Add upgrade guide for Middleware. (#37382) * Middleware upgrade guide * Add a bit more * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> Co-authored-by: Edward Thomson <ethomson@github.com> Co-authored-by: Dominik Ferber <dominik.ferber@gmail.com> * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> * Updates based on PR comments * Add before / after * Flip paragraphs * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> * Apply suggestions from code review Co-authored-by: Kiko Beats <josefrancisco.verdu@gmail.com> * Apply suggestions from code review * Apply suggestions from code review * Apply suggestions from code review Co-authored-by: Damien Simonin Feugas <damien.feugas@gmail.com> * Update errors/middleware-upgrade-guide.md Co-authored-by: Dom Sip <dominik.sipowicz@gmail.com> * Update errors/middleware-upgrade-guide.md Co-authored-by: Damien Simonin Feugas <damien.feugas@gmail.com> * Update middleware-upgrade-guide.md * Update errors/middleware-upgrade-guide.md Co-authored-by: Rich Haines <hello@richardhaines.dev> * Update errors/middleware-upgrade-guide.md Co-authored-by: Rich Haines <hello@richardhaines.dev> * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> * Apply suggestions from code review * Update errors/middleware-upgrade-guide.md Co-authored-by: Rich Haines <hello@richardhaines.dev> Co-authored-by: Edward Thomson <ethomson@github.com> Co-authored-by: Dominik Ferber <dominik.ferber@gmail.com> Co-authored-by: Kiko Beats <josefrancisco.verdu@gmail.com> Co-authored-by: Damien Simonin Feugas <damien.feugas@gmail.com> Co-authored-by: Dom Sip <dominik.sipowicz@gmail.com>
2022-06-16 18:29:18 +02:00
### Explanation
To help ensure security, we are removing the ability to send response bodies in Middleware. This ensures that Middleware is only used to `rewrite`, `redirect`, or modify the incoming request (e.g. [setting cookies](#cookies-api-revamped)).
The following patterns will no longer work:
```js
new Response('a text value')
new Response(streamOrBuffer)
new Response(JSON.stringify(obj), { headers: 'application/json' })
NextResponse.json()
```
### How to upgrade
For cases where Middleware is used to respond (such as authorization), you should migrate to use `rewrite`/`redirect` to pages that show an authorization error, login forms, or to an API Route.
Add upgrade guide for Middleware. (#37382) * Middleware upgrade guide * Add a bit more * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> Co-authored-by: Edward Thomson <ethomson@github.com> Co-authored-by: Dominik Ferber <dominik.ferber@gmail.com> * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> * Updates based on PR comments * Add before / after * Flip paragraphs * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> * Apply suggestions from code review Co-authored-by: Kiko Beats <josefrancisco.verdu@gmail.com> * Apply suggestions from code review * Apply suggestions from code review * Apply suggestions from code review Co-authored-by: Damien Simonin Feugas <damien.feugas@gmail.com> * Update errors/middleware-upgrade-guide.md Co-authored-by: Dom Sip <dominik.sipowicz@gmail.com> * Update errors/middleware-upgrade-guide.md Co-authored-by: Damien Simonin Feugas <damien.feugas@gmail.com> * Update middleware-upgrade-guide.md * Update errors/middleware-upgrade-guide.md Co-authored-by: Rich Haines <hello@richardhaines.dev> * Update errors/middleware-upgrade-guide.md Co-authored-by: Rich Haines <hello@richardhaines.dev> * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> * Apply suggestions from code review * Update errors/middleware-upgrade-guide.md Co-authored-by: Rich Haines <hello@richardhaines.dev> Co-authored-by: Edward Thomson <ethomson@github.com> Co-authored-by: Dominik Ferber <dominik.ferber@gmail.com> Co-authored-by: Kiko Beats <josefrancisco.verdu@gmail.com> Co-authored-by: Damien Simonin Feugas <damien.feugas@gmail.com> Co-authored-by: Dom Sip <dominik.sipowicz@gmail.com>
2022-06-16 18:29:18 +02:00
#### Before
```typescript
// pages/_middleware.ts
import { NextResponse } from 'next/server'
import type { NextRequest } from 'next/server'
import { isAuthValid } from './lib/auth'
export function middleware(request: NextRequest) {
// Example function to validate auth
if (isAuthValid(req)) {
return NextResponse.next()
}
return NextResponse.json({ message: 'Auth required' }, { status: 401 })
}
```
#### After
```typescript
// middleware.ts
import { NextResponse } from 'next/server'
import type { NextRequest } from 'next/server'
import { isAuthValid } from './lib/auth'
export function middleware(request: NextRequest) {
// Example function to validate auth
if (isAuthValid(req)) {
return NextResponse.next()
}
const loginUrl = new URL('/login', request.url)
loginUrl.searchParams.set('from', request.nextUrl.pathname)
return NextResponse.redirect(loginUrl)
}
```
Middleware docs update (#38111) * Initial outline added for middleware docs * Feedback changes - not included new user agent yet * edge api routes docs * middleware page some cleanup * moved api stuff to next server, added useragent * waitUntil example added * Updated env vars section * Added cookies on the request object example * fixed naming * fixed import typo * Amy feedback * Update docs/advanced-features/middleware.md Co-authored-by: Amy Burns <amy.burns@vercel.com> * first commit * more fixes * re-structuring based on feedback * changes to middleware.md * updates to edge-api-routes * code typo * Update docs/advanced-features/middleware.md Co-authored-by: JJ Kasper <jj@jjsweb.site> * Update edge-api-routes.md * Update Edge Runtime API docs * Clarify API docs * Update * Update docs/advanced-features/middleware.md * Update switchable runtime docs * Update response * experimental-edge * Update docs/advanced-features/middleware.md * Add example of forwarding headers and address comments * Add proxying headers to middleware upgrade guide * Apply suggestions from code review Co-authored-by: Jeff Escalante <jescalan@users.noreply.github.com> * fix middleware directory spec * localization explanation * update detecting runtime * Update docs/advanced-features/react-18/switchable-runtime.md Co-authored-by: Balázs Orbán <info@balazsorban.com> * fix prettier issues * table fix * Update docs/advanced-features/react-18/switchable-runtime.md Co-authored-by: Jeff Escalante <jescalan@users.noreply.github.com> * Update docs/api-routes/edge-api-routes.md Co-authored-by: Jeff Escalante <jescalan@users.noreply.github.com> * lint-fix Co-authored-by: molebox <hello@richardhaines.dev> Co-authored-by: Amy Burns <amy.burns@vercel.com> Co-authored-by: Ismael Rumzan <ismael.rumzan@gmail.com> Co-authored-by: Lee Robinson <me@leerob.io> Co-authored-by: Balázs Orbán <info@balazsorban.com> Co-authored-by: Jeff Escalante <jescalan@users.noreply.github.com> Co-authored-by: Ismael <ismael@vercel.com>
2022-06-28 17:22:48 +02:00
#### Edge API Routes
If you were previously using Middleware to forward headers to an external API, you can now use [Edge API Routes](/docs/api-routes/edge-api-routes):
```typescript
// pages/api/proxy.ts
import { type NextRequest } from 'next/server'
export const config = {
runtime: 'experimental-edge',
}
export default async function handler(req: NextRequest) {
const authorization = req.cookies.get('authorization')
return fetch('https://backend-api.com/api/protected', {
method: req.method,
headers: {
authorization,
},
redirect: 'manual',
})
}
```
Add upgrade guide for Middleware. (#37382) * Middleware upgrade guide * Add a bit more * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> Co-authored-by: Edward Thomson <ethomson@github.com> Co-authored-by: Dominik Ferber <dominik.ferber@gmail.com> * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> * Updates based on PR comments * Add before / after * Flip paragraphs * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> * Apply suggestions from code review Co-authored-by: Kiko Beats <josefrancisco.verdu@gmail.com> * Apply suggestions from code review * Apply suggestions from code review * Apply suggestions from code review Co-authored-by: Damien Simonin Feugas <damien.feugas@gmail.com> * Update errors/middleware-upgrade-guide.md Co-authored-by: Dom Sip <dominik.sipowicz@gmail.com> * Update errors/middleware-upgrade-guide.md Co-authored-by: Damien Simonin Feugas <damien.feugas@gmail.com> * Update middleware-upgrade-guide.md * Update errors/middleware-upgrade-guide.md Co-authored-by: Rich Haines <hello@richardhaines.dev> * Update errors/middleware-upgrade-guide.md Co-authored-by: Rich Haines <hello@richardhaines.dev> * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> * Apply suggestions from code review * Update errors/middleware-upgrade-guide.md Co-authored-by: Rich Haines <hello@richardhaines.dev> Co-authored-by: Edward Thomson <ethomson@github.com> Co-authored-by: Dominik Ferber <dominik.ferber@gmail.com> Co-authored-by: Kiko Beats <josefrancisco.verdu@gmail.com> Co-authored-by: Damien Simonin Feugas <damien.feugas@gmail.com> Co-authored-by: Dom Sip <dominik.sipowicz@gmail.com>
2022-06-16 18:29:18 +02:00
## Cookies API Revamped
### Summary of changes
| Added | Removed |
| ----------------------- | ------------- |
| `cookie.set` | `cookie` |
| `cookie.delete` | `clearCookie` |
| `cookie.getWithOptions` | `cookies` |
### Explanation
Based on beta feedback, we are changing the Cookies API in `NextRequest` and `NextResponse` to align more to a `get`/`set` model. The `Cookies` API extends Map, including methods like [entries](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries) and [values](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries).
### How to upgrade
`NextResponse` now has a `cookies` instance with:
- `cookie.delete`
- `cookie.set`
- `cookie.getWithOptions`
As well as other extended methods from `Map`.
#### Before
```javascript
// pages/_middleware.ts
Add upgrade guide for Middleware. (#37382) * Middleware upgrade guide * Add a bit more * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> Co-authored-by: Edward Thomson <ethomson@github.com> Co-authored-by: Dominik Ferber <dominik.ferber@gmail.com> * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> * Updates based on PR comments * Add before / after * Flip paragraphs * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> * Apply suggestions from code review Co-authored-by: Kiko Beats <josefrancisco.verdu@gmail.com> * Apply suggestions from code review * Apply suggestions from code review * Apply suggestions from code review Co-authored-by: Damien Simonin Feugas <damien.feugas@gmail.com> * Update errors/middleware-upgrade-guide.md Co-authored-by: Dom Sip <dominik.sipowicz@gmail.com> * Update errors/middleware-upgrade-guide.md Co-authored-by: Damien Simonin Feugas <damien.feugas@gmail.com> * Update middleware-upgrade-guide.md * Update errors/middleware-upgrade-guide.md Co-authored-by: Rich Haines <hello@richardhaines.dev> * Update errors/middleware-upgrade-guide.md Co-authored-by: Rich Haines <hello@richardhaines.dev> * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> * Apply suggestions from code review * Update errors/middleware-upgrade-guide.md Co-authored-by: Rich Haines <hello@richardhaines.dev> Co-authored-by: Edward Thomson <ethomson@github.com> Co-authored-by: Dominik Ferber <dominik.ferber@gmail.com> Co-authored-by: Kiko Beats <josefrancisco.verdu@gmail.com> Co-authored-by: Damien Simonin Feugas <damien.feugas@gmail.com> Co-authored-by: Dom Sip <dominik.sipowicz@gmail.com>
2022-06-16 18:29:18 +02:00
import { NextResponse } from 'next/server'
import type { NextRequest } from 'next/server'
export function middleware(request: NextRequest) {
// create an instance of the class to access the public methods. This uses `next()`,
// you could use `redirect()` or `rewrite()` as well
let response = NextResponse.next()
// get the cookies from the request
let cookieFromRequest = request.cookies['my-cookie']
// set the `cookie`
response.cookie('hello', 'world')
// set the `cookie` with options
const cookieWithOptions = response.cookie('hello', 'world', {
path: '/',
maxAge: 1000 * 60 * 60 * 24 * 7,
httpOnly: true,
sameSite: 'strict',
domain: 'example.com',
})
// clear the `cookie`
response.clearCookie('hello')
return response
}
```
#### After
```typescript
// middleware.ts
export function middleware() {
const response = new NextResponse()
// set a cookie
response.cookies.set('vercel', 'fast')
// set another cookie with options
response.cookies.set('nextjs', 'awesome', { path: '/test' })
// get all the details of a cookie
const { value, options } = response.cookies.getWithOptions('vercel')
Add upgrade guide for Middleware. (#37382) * Middleware upgrade guide * Add a bit more * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> Co-authored-by: Edward Thomson <ethomson@github.com> Co-authored-by: Dominik Ferber <dominik.ferber@gmail.com> * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> * Updates based on PR comments * Add before / after * Flip paragraphs * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> * Apply suggestions from code review Co-authored-by: Kiko Beats <josefrancisco.verdu@gmail.com> * Apply suggestions from code review * Apply suggestions from code review * Apply suggestions from code review Co-authored-by: Damien Simonin Feugas <damien.feugas@gmail.com> * Update errors/middleware-upgrade-guide.md Co-authored-by: Dom Sip <dominik.sipowicz@gmail.com> * Update errors/middleware-upgrade-guide.md Co-authored-by: Damien Simonin Feugas <damien.feugas@gmail.com> * Update middleware-upgrade-guide.md * Update errors/middleware-upgrade-guide.md Co-authored-by: Rich Haines <hello@richardhaines.dev> * Update errors/middleware-upgrade-guide.md Co-authored-by: Rich Haines <hello@richardhaines.dev> * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> * Apply suggestions from code review * Update errors/middleware-upgrade-guide.md Co-authored-by: Rich Haines <hello@richardhaines.dev> Co-authored-by: Edward Thomson <ethomson@github.com> Co-authored-by: Dominik Ferber <dominik.ferber@gmail.com> Co-authored-by: Kiko Beats <josefrancisco.verdu@gmail.com> Co-authored-by: Damien Simonin Feugas <damien.feugas@gmail.com> Co-authored-by: Dom Sip <dominik.sipowicz@gmail.com>
2022-06-16 18:29:18 +02:00
console.log(value) // => 'fast'
console.log(options) // => { Path: '/test' }
// deleting a cookie will mark it as expired
response.cookies.delete('vercel')
// clear all cookies means mark all of them as expired
response.cookies.clear()
return response
Add upgrade guide for Middleware. (#37382) * Middleware upgrade guide * Add a bit more * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> Co-authored-by: Edward Thomson <ethomson@github.com> Co-authored-by: Dominik Ferber <dominik.ferber@gmail.com> * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> * Updates based on PR comments * Add before / after * Flip paragraphs * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> * Apply suggestions from code review Co-authored-by: Kiko Beats <josefrancisco.verdu@gmail.com> * Apply suggestions from code review * Apply suggestions from code review * Apply suggestions from code review Co-authored-by: Damien Simonin Feugas <damien.feugas@gmail.com> * Update errors/middleware-upgrade-guide.md Co-authored-by: Dom Sip <dominik.sipowicz@gmail.com> * Update errors/middleware-upgrade-guide.md Co-authored-by: Damien Simonin Feugas <damien.feugas@gmail.com> * Update middleware-upgrade-guide.md * Update errors/middleware-upgrade-guide.md Co-authored-by: Rich Haines <hello@richardhaines.dev> * Update errors/middleware-upgrade-guide.md Co-authored-by: Rich Haines <hello@richardhaines.dev> * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> * Apply suggestions from code review * Update errors/middleware-upgrade-guide.md Co-authored-by: Rich Haines <hello@richardhaines.dev> Co-authored-by: Edward Thomson <ethomson@github.com> Co-authored-by: Dominik Ferber <dominik.ferber@gmail.com> Co-authored-by: Kiko Beats <josefrancisco.verdu@gmail.com> Co-authored-by: Damien Simonin Feugas <damien.feugas@gmail.com> Co-authored-by: Dom Sip <dominik.sipowicz@gmail.com>
2022-06-16 18:29:18 +02:00
}
```
Add upgrade guide for Middleware. (#37382) * Middleware upgrade guide * Add a bit more * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> Co-authored-by: Edward Thomson <ethomson@github.com> Co-authored-by: Dominik Ferber <dominik.ferber@gmail.com> * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> * Updates based on PR comments * Add before / after * Flip paragraphs * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> * Apply suggestions from code review Co-authored-by: Kiko Beats <josefrancisco.verdu@gmail.com> * Apply suggestions from code review * Apply suggestions from code review * Apply suggestions from code review Co-authored-by: Damien Simonin Feugas <damien.feugas@gmail.com> * Update errors/middleware-upgrade-guide.md Co-authored-by: Dom Sip <dominik.sipowicz@gmail.com> * Update errors/middleware-upgrade-guide.md Co-authored-by: Damien Simonin Feugas <damien.feugas@gmail.com> * Update middleware-upgrade-guide.md * Update errors/middleware-upgrade-guide.md Co-authored-by: Rich Haines <hello@richardhaines.dev> * Update errors/middleware-upgrade-guide.md Co-authored-by: Rich Haines <hello@richardhaines.dev> * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> * Apply suggestions from code review * Update errors/middleware-upgrade-guide.md Co-authored-by: Rich Haines <hello@richardhaines.dev> Co-authored-by: Edward Thomson <ethomson@github.com> Co-authored-by: Dominik Ferber <dominik.ferber@gmail.com> Co-authored-by: Kiko Beats <josefrancisco.verdu@gmail.com> Co-authored-by: Damien Simonin Feugas <damien.feugas@gmail.com> Co-authored-by: Dom Sip <dominik.sipowicz@gmail.com>
2022-06-16 18:29:18 +02:00
## New User-Agent Helper
### Summary of changes
- Accessing the user agent is no longer available on the request object
- We've added a new `userAgent` helper to reduce Middleware size by `17kb`
### Explanation
To help reduce the size of your Middleware, we have extracted the user agent from the request object and created a new helper `userAgent`.
Add upgrade guide for Middleware. (#37382) * Middleware upgrade guide * Add a bit more * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> Co-authored-by: Edward Thomson <ethomson@github.com> Co-authored-by: Dominik Ferber <dominik.ferber@gmail.com> * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> * Updates based on PR comments * Add before / after * Flip paragraphs * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> * Apply suggestions from code review Co-authored-by: Kiko Beats <josefrancisco.verdu@gmail.com> * Apply suggestions from code review * Apply suggestions from code review * Apply suggestions from code review Co-authored-by: Damien Simonin Feugas <damien.feugas@gmail.com> * Update errors/middleware-upgrade-guide.md Co-authored-by: Dom Sip <dominik.sipowicz@gmail.com> * Update errors/middleware-upgrade-guide.md Co-authored-by: Damien Simonin Feugas <damien.feugas@gmail.com> * Update middleware-upgrade-guide.md * Update errors/middleware-upgrade-guide.md Co-authored-by: Rich Haines <hello@richardhaines.dev> * Update errors/middleware-upgrade-guide.md Co-authored-by: Rich Haines <hello@richardhaines.dev> * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> * Apply suggestions from code review * Update errors/middleware-upgrade-guide.md Co-authored-by: Rich Haines <hello@richardhaines.dev> Co-authored-by: Edward Thomson <ethomson@github.com> Co-authored-by: Dominik Ferber <dominik.ferber@gmail.com> Co-authored-by: Kiko Beats <josefrancisco.verdu@gmail.com> Co-authored-by: Damien Simonin Feugas <damien.feugas@gmail.com> Co-authored-by: Dom Sip <dominik.sipowicz@gmail.com>
2022-06-16 18:29:18 +02:00
The helper is imported from `next/server` and allows you to opt in to using the user agent. The helper gives you access to the same properties that were available from the request object.
### How to upgrade
- Import the `userAgent` helper from `next/server`
- Destructure the properties you need to work with
#### Before
```typescript
// pages/_middleware.ts
Add upgrade guide for Middleware. (#37382) * Middleware upgrade guide * Add a bit more * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> Co-authored-by: Edward Thomson <ethomson@github.com> Co-authored-by: Dominik Ferber <dominik.ferber@gmail.com> * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> * Updates based on PR comments * Add before / after * Flip paragraphs * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> * Apply suggestions from code review Co-authored-by: Kiko Beats <josefrancisco.verdu@gmail.com> * Apply suggestions from code review * Apply suggestions from code review * Apply suggestions from code review Co-authored-by: Damien Simonin Feugas <damien.feugas@gmail.com> * Update errors/middleware-upgrade-guide.md Co-authored-by: Dom Sip <dominik.sipowicz@gmail.com> * Update errors/middleware-upgrade-guide.md Co-authored-by: Damien Simonin Feugas <damien.feugas@gmail.com> * Update middleware-upgrade-guide.md * Update errors/middleware-upgrade-guide.md Co-authored-by: Rich Haines <hello@richardhaines.dev> * Update errors/middleware-upgrade-guide.md Co-authored-by: Rich Haines <hello@richardhaines.dev> * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> * Apply suggestions from code review * Update errors/middleware-upgrade-guide.md Co-authored-by: Rich Haines <hello@richardhaines.dev> Co-authored-by: Edward Thomson <ethomson@github.com> Co-authored-by: Dominik Ferber <dominik.ferber@gmail.com> Co-authored-by: Kiko Beats <josefrancisco.verdu@gmail.com> Co-authored-by: Damien Simonin Feugas <damien.feugas@gmail.com> Co-authored-by: Dom Sip <dominik.sipowicz@gmail.com>
2022-06-16 18:29:18 +02:00
import { NextRequest, NextResponse } from 'next/server'
export function middleware(request: NextRequest) {
const url = request.nextUrl
const viewport = request.ua.device.type === 'mobile' ? 'mobile' : 'desktop'
url.searchParams.set('viewport', viewport)
return NextResponse.rewrite(url)
Add upgrade guide for Middleware. (#37382) * Middleware upgrade guide * Add a bit more * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> Co-authored-by: Edward Thomson <ethomson@github.com> Co-authored-by: Dominik Ferber <dominik.ferber@gmail.com> * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> * Updates based on PR comments * Add before / after * Flip paragraphs * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> * Apply suggestions from code review Co-authored-by: Kiko Beats <josefrancisco.verdu@gmail.com> * Apply suggestions from code review * Apply suggestions from code review * Apply suggestions from code review Co-authored-by: Damien Simonin Feugas <damien.feugas@gmail.com> * Update errors/middleware-upgrade-guide.md Co-authored-by: Dom Sip <dominik.sipowicz@gmail.com> * Update errors/middleware-upgrade-guide.md Co-authored-by: Damien Simonin Feugas <damien.feugas@gmail.com> * Update middleware-upgrade-guide.md * Update errors/middleware-upgrade-guide.md Co-authored-by: Rich Haines <hello@richardhaines.dev> * Update errors/middleware-upgrade-guide.md Co-authored-by: Rich Haines <hello@richardhaines.dev> * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> * Apply suggestions from code review * Update errors/middleware-upgrade-guide.md Co-authored-by: Rich Haines <hello@richardhaines.dev> Co-authored-by: Edward Thomson <ethomson@github.com> Co-authored-by: Dominik Ferber <dominik.ferber@gmail.com> Co-authored-by: Kiko Beats <josefrancisco.verdu@gmail.com> Co-authored-by: Damien Simonin Feugas <damien.feugas@gmail.com> Co-authored-by: Dom Sip <dominik.sipowicz@gmail.com>
2022-06-16 18:29:18 +02:00
}
```
#### After
```typescript
// middleware.ts
import { NextRequest, NextResponse, userAgent } from 'next/server'
export function middleware(request: NextRequest) {
const url = request.nextUrl
const { device } = userAgent(request)
const viewport = device.type === 'mobile' ? 'mobile' : 'desktop'
url.searchParams.set('viewport', viewport)
return NextResponse.rewrite(url)
Add upgrade guide for Middleware. (#37382) * Middleware upgrade guide * Add a bit more * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> Co-authored-by: Edward Thomson <ethomson@github.com> Co-authored-by: Dominik Ferber <dominik.ferber@gmail.com> * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> * Updates based on PR comments * Add before / after * Flip paragraphs * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> * Apply suggestions from code review Co-authored-by: Kiko Beats <josefrancisco.verdu@gmail.com> * Apply suggestions from code review * Apply suggestions from code review * Apply suggestions from code review Co-authored-by: Damien Simonin Feugas <damien.feugas@gmail.com> * Update errors/middleware-upgrade-guide.md Co-authored-by: Dom Sip <dominik.sipowicz@gmail.com> * Update errors/middleware-upgrade-guide.md Co-authored-by: Damien Simonin Feugas <damien.feugas@gmail.com> * Update middleware-upgrade-guide.md * Update errors/middleware-upgrade-guide.md Co-authored-by: Rich Haines <hello@richardhaines.dev> * Update errors/middleware-upgrade-guide.md Co-authored-by: Rich Haines <hello@richardhaines.dev> * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> * Apply suggestions from code review * Update errors/middleware-upgrade-guide.md Co-authored-by: Rich Haines <hello@richardhaines.dev> Co-authored-by: Edward Thomson <ethomson@github.com> Co-authored-by: Dominik Ferber <dominik.ferber@gmail.com> Co-authored-by: Kiko Beats <josefrancisco.verdu@gmail.com> Co-authored-by: Damien Simonin Feugas <damien.feugas@gmail.com> Co-authored-by: Dom Sip <dominik.sipowicz@gmail.com>
2022-06-16 18:29:18 +02:00
}
```
## No More Page Match Data
### Summary of changes
- Use [`URLPattern`](https://developer.mozilla.org/en-US/docs/Web/API/URLPattern) to check if a Middleware is being invoked for a certain page match
### Explanation
Currently, Middleware estimates whether you are serving an asset of a Page based on the Next.js routes manifest (internal configuration). This value is surfaced through `request.page`.
To make page and asset matching more accurate, we are now using the web standard `URLPattern` API.
### How to upgrade
Use [`URLPattern`](https://developer.mozilla.org/en-US/docs/Web/API/URLPattern) to check if a Middleware is being invoked for a certain page match.
#### Before
```typescript
// pages/_middleware.ts
Add upgrade guide for Middleware. (#37382) * Middleware upgrade guide * Add a bit more * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> Co-authored-by: Edward Thomson <ethomson@github.com> Co-authored-by: Dominik Ferber <dominik.ferber@gmail.com> * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> * Updates based on PR comments * Add before / after * Flip paragraphs * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> * Apply suggestions from code review Co-authored-by: Kiko Beats <josefrancisco.verdu@gmail.com> * Apply suggestions from code review * Apply suggestions from code review * Apply suggestions from code review Co-authored-by: Damien Simonin Feugas <damien.feugas@gmail.com> * Update errors/middleware-upgrade-guide.md Co-authored-by: Dom Sip <dominik.sipowicz@gmail.com> * Update errors/middleware-upgrade-guide.md Co-authored-by: Damien Simonin Feugas <damien.feugas@gmail.com> * Update middleware-upgrade-guide.md * Update errors/middleware-upgrade-guide.md Co-authored-by: Rich Haines <hello@richardhaines.dev> * Update errors/middleware-upgrade-guide.md Co-authored-by: Rich Haines <hello@richardhaines.dev> * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> * Apply suggestions from code review * Update errors/middleware-upgrade-guide.md Co-authored-by: Rich Haines <hello@richardhaines.dev> Co-authored-by: Edward Thomson <ethomson@github.com> Co-authored-by: Dominik Ferber <dominik.ferber@gmail.com> Co-authored-by: Kiko Beats <josefrancisco.verdu@gmail.com> Co-authored-by: Damien Simonin Feugas <damien.feugas@gmail.com> Co-authored-by: Dom Sip <dominik.sipowicz@gmail.com>
2022-06-16 18:29:18 +02:00
import { NextResponse } from 'next/server'
import type { NextRequest } from 'next/server'
export function middleware(request: NextRequest) {
const { params } = event.request.page
const { locale, slug } = params
if (locale && slug) {
const { search, protocol, host } = request.nextUrl
const url = new URL(`${protocol}//${locale}.${host}/${slug}${search}`)
return NextResponse.redirect(url)
}
}
```
#### After
```typescript
// middleware.ts
import { NextResponse } from 'next/server'
import type { NextRequest } from 'next/server'
const PATTERNS = [
[
new URLPattern({ pathname: '/:locale/:slug' }),
({ pathname }) => pathname.groups,
],
]
const params = (url) => {
const input = url.split('?')[0]
let result = {}
for (const [pattern, handler] of PATTERNS) {
const patternResult = pattern.exec(input)
if (patternResult !== null && 'pathname' in patternResult) {
result = handler(patternResult)
break
}
}
return result
}
export function middleware(request: NextRequest) {
const { locale, slug } = params(request.url)
if (locale && slug) {
const { search, protocol, host } = request.nextUrl
const url = new URL(`${protocol}//${locale}.${host}/${slug}${search}`)
return NextResponse.redirect(url)
}
}
```
## Executing Middleware on Internal Next.js Requests
### Summary of changes
- Middleware will be executed for _all_ requests, including `_next`
### Explanation
Prior to Next.js `v12.2`, Middleware was not executed for `_next` requests.
For cases where Middleware is used for authorization, you should migrate to use `rewrite`/`redirect` to Pages that show an authorization error, login forms, or to an API Route.
Add upgrade guide for Middleware. (#37382) * Middleware upgrade guide * Add a bit more * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> Co-authored-by: Edward Thomson <ethomson@github.com> Co-authored-by: Dominik Ferber <dominik.ferber@gmail.com> * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> * Updates based on PR comments * Add before / after * Flip paragraphs * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> * Apply suggestions from code review Co-authored-by: Kiko Beats <josefrancisco.verdu@gmail.com> * Apply suggestions from code review * Apply suggestions from code review * Apply suggestions from code review Co-authored-by: Damien Simonin Feugas <damien.feugas@gmail.com> * Update errors/middleware-upgrade-guide.md Co-authored-by: Dom Sip <dominik.sipowicz@gmail.com> * Update errors/middleware-upgrade-guide.md Co-authored-by: Damien Simonin Feugas <damien.feugas@gmail.com> * Update middleware-upgrade-guide.md * Update errors/middleware-upgrade-guide.md Co-authored-by: Rich Haines <hello@richardhaines.dev> * Update errors/middleware-upgrade-guide.md Co-authored-by: Rich Haines <hello@richardhaines.dev> * Apply suggestions from code review Co-authored-by: Rich Haines <hello@richardhaines.dev> * Apply suggestions from code review * Update errors/middleware-upgrade-guide.md Co-authored-by: Rich Haines <hello@richardhaines.dev> Co-authored-by: Edward Thomson <ethomson@github.com> Co-authored-by: Dominik Ferber <dominik.ferber@gmail.com> Co-authored-by: Kiko Beats <josefrancisco.verdu@gmail.com> Co-authored-by: Damien Simonin Feugas <damien.feugas@gmail.com> Co-authored-by: Dom Sip <dominik.sipowicz@gmail.com>
2022-06-16 18:29:18 +02:00
See [No Reponse Body](#no-response-body) for an example of how to migrate to use `rewrite`/`redirect`.