2023-07-05 15:11:16 +02:00
|
|
|
---
|
|
|
|
title: Deprecated Middleware API Signature
|
|
|
|
---
|
2021-10-26 17:03:39 +02:00
|
|
|
|
2023-07-05 15:11:16 +02:00
|
|
|
## Why This Error Occurred
|
2021-10-26 17:03:39 +02:00
|
|
|
|
|
|
|
Your application is using a Middleware function that is using parameters from the deprecated API.
|
|
|
|
|
2023-07-05 15:11:16 +02:00
|
|
|
```ts filename="middleware.ts"
|
2021-10-26 17:03:39 +02:00
|
|
|
import { NextResponse } from 'next/server'
|
|
|
|
|
|
|
|
export function middleware(event) {
|
|
|
|
if (event.request.nextUrl.pathname === '/blocked') {
|
|
|
|
event.respondWith(
|
|
|
|
new NextResponse(null, {
|
|
|
|
status: 403,
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2023-07-05 15:11:16 +02:00
|
|
|
## Possible Ways to Fix It
|
2021-10-26 17:03:39 +02:00
|
|
|
|
|
|
|
Update to use the new API for Middleware:
|
|
|
|
|
2023-07-05 15:11:16 +02:00
|
|
|
```ts filename="middleware.ts"
|
2021-10-26 17:03:39 +02:00
|
|
|
import { NextResponse } from 'next/server'
|
|
|
|
|
|
|
|
export function middleware(request) {
|
|
|
|
if (request.nextUrl.pathname === '/blocked') {
|
|
|
|
return new NextResponse(null, {
|
|
|
|
status: 403,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|