forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve deprecation errors for new middleware API (vercel#30316)
Co-authored-by: JJ Kasper <[email protected]> Co-authored-by: Steven <[email protected]>
- Loading branch information
1 parent
8b85801
commit c497b3a
Showing
7 changed files
with
87 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Deprecated Middleware API Signature | ||
|
||
#### Why This Error Occurred | ||
|
||
Your application is using a Middleware function that is using parameters from the deprecated API. | ||
|
||
```typescript | ||
// _middleware.js | ||
import { NextResponse } from 'next/server' | ||
|
||
export function middleware(event) { | ||
if (event.request.nextUrl.pathname === '/blocked') { | ||
event.respondWith( | ||
new NextResponse(null, { | ||
status: 403, | ||
}) | ||
) | ||
} | ||
} | ||
``` | ||
|
||
#### Possible Ways to Fix It | ||
|
||
Update to use the new API for Middleware: | ||
|
||
```typescript | ||
// _middleware.js | ||
import { NextResponse } from 'next/server' | ||
|
||
export function middleware(request) { | ||
if (request.nextUrl.pathname === '/blocked') { | ||
return new NextResponse(null, { | ||
status: 403, | ||
}) | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
export class DeprecationError extends Error { | ||
constructor() { | ||
super(`Middleware now accepts an async API directly with the form: | ||
constructor({ page }: { page: string }) { | ||
super(`The middleware "${page}" accepts an async API directly with the form: | ||
export function middleware(request, event) { | ||
return new Response("Hello " + request.url) | ||
} | ||
Read more: https://nextjs.org/docs/messages/middleware-new-signature | ||
`) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters