Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TS types for NextMiddleware #30578

Merged
merged 22 commits into from Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/next/server.d.ts
@@ -1,3 +1,4 @@
export { NextFetchEvent } from 'next/dist/server/web/spec-extension/fetch-event'
export { NextRequest } from 'next/dist/server/web/spec-extension/request'
export { NextResponse } from 'next/dist/server/web/spec-extension/response'
export { NextMiddleware } from 'next/server/web/types'
4 changes: 2 additions & 2 deletions packages/next/server/web/adapter.ts
@@ -1,4 +1,4 @@
import type { RequestData, FetchEventResult } from './types'
import type { NextMiddleware, RequestData, FetchEventResult } from './types'
import { DeprecationError } from './error'
import { fromNodeHeaders } from './utils'
import { NextFetchEvent } from './spec-extension/fetch-event'
Expand All @@ -7,7 +7,7 @@ import { NextResponse } from './spec-extension/response'
import { waitUntilSymbol } from './spec-compliant/fetch-event'

export async function adapter(params: {
handler: (request: NextRequest, event: NextFetchEvent) => Promise<Response>
handler: NextMiddleware
page: string
request: RequestData
}): Promise<FetchEventResult> {
Expand Down
7 changes: 7 additions & 0 deletions packages/next/server/web/types.ts
@@ -1,4 +1,6 @@
import type { I18NConfig } from '../config-shared'
import type { NextRequest } from '../web/spec-extension/request'
import type { NextFetchEvent } from '../web/spec-extension/fetch-event'

export interface NodeHeaders {
[header: string]: string | string[] | undefined
Expand Down Expand Up @@ -29,3 +31,8 @@ export interface FetchEventResult {
response: Response
waitUntil: Promise<any>
}

export type NextMiddleware = (
request: NextRequest,
event: NextFetchEvent
) => Promise<Response | null>