5d1f33f5c4
Something I noticed while using Middleware is that the older and no longer working methods are still accessible for the `event` with autocompletion because of their types, and the way of knowing they're deprecated is by running the app and seeing the error message, this should improve that when coding in tools like VS Code. ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [x] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have helpful link attached, see `contributing.md` ## Documentation / Examples - [ ] Make sure the linting passes by running `yarn lint` Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
34 lines
853 B
TypeScript
34 lines
853 B
TypeScript
import { DeprecationError } from '../error'
|
|
import { FetchEvent } from '../spec-compliant/fetch-event'
|
|
import { NextRequest } from './request'
|
|
|
|
export class NextFetchEvent extends FetchEvent {
|
|
sourcePage: string
|
|
|
|
constructor(params: { request: NextRequest; page: string }) {
|
|
super(params.request)
|
|
this.sourcePage = params.page
|
|
}
|
|
|
|
/**
|
|
* @deprecated The `request` is now the first parameter and the API is now async.
|
|
*
|
|
* Read more: https://nextjs.org/docs/messages/middleware-new-signature
|
|
*/
|
|
get request() {
|
|
throw new DeprecationError({
|
|
page: this.sourcePage,
|
|
})
|
|
}
|
|
|
|
/**
|
|
* @deprecated Using `respondWith` is no longer needed.
|
|
*
|
|
* Read more: https://nextjs.org/docs/messages/middleware-new-signature
|
|
*/
|
|
respondWith() {
|
|
throw new DeprecationError({
|
|
page: this.sourcePage,
|
|
})
|
|
}
|
|
}
|