Deployment & Environment Variables in Next.js Quiz – 15 Questions with Answers
15 questions · 12 min · Medium
Test your knowledge of Middleware in Next.js, including request interception, authentication, redirects, rewrites, cookies, headers, matchers, and middleware configuration.
No sign-up needed · Last updated:
Score: 0 00:00
Create a free account to keep your scores and track your progress. It is optional.
15 questions · 12 min · Medium
15 questions · 12 min · Medium
20 questions · 15 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
A. To intercept and process requests before they reach a route
Middleware can run logic on incoming requests before the request is handled by the destination route.
A. NextResponse
NextResponse provides helpers for creating responses, redirects, rewrites, and other middleware behavior.
A. NextRequest
NextRequest extends the standard Request API with Next.js-specific functionality useful in Middleware.
A. NextResponse.next()
NextResponse.next() indicates that processing should continue to the next stage of the request.
A. redirect
NextResponse.redirect() can be used in Middleware to redirect a request to another URL.
A. Authentication and authorization checks
Middleware is often used to inspect requests and apply authentication or authorization logic before allowing access.
B. Rewrite
A rewrite changes the destination used to handle a request while keeping the original URL visible to the browser.
B. matcher
The matcher configuration allows Middleware to be applied selectively to specified URL patterns.
A. Cookies and headers
NextRequest provides access to request information such as headers, cookies, URL details, and other request properties.
B. It can run before a request reaches the destination route
Middleware operates in the request-processing pipeline and can modify or respond to a request before the destination is reached.
A. middleware.js
The traditional Next.js Middleware convention uses a middleware.js or middleware.ts file at the appropriate project root location.
A. request.nextUrl
NextRequest provides nextUrl, which exposes parsed URL information and Next.js-specific URL functionality.
A. Using request.cookies
Middleware can inspect cookies on the incoming request through the cookies API available on NextRequest.
A. Call NextResponse.next()
When no redirect, rewrite, or other response is required, NextResponse.next() allows request processing to continue.
B. It provides request-time logic that can influence routing and responses
Middleware enables request-time processing such as authentication checks, redirects, rewrites, and request or response manipulation.