Next.js API Route Gives Unexpected 'undefined' for Query Parameters When Using Middleware
I'm not sure how to approach I'm performance testing and I'm working with an scenario with a Next.js API route where I'm trying to access query parameters, but I'm getting 'undefined' values. I'm utilizing middleware to check for a valid API key before proceeding with the main logic. The middleware is supposed to validate the request and then call `next()`, but it seems to be interfering with the query parameters. Here's my middleware code: ```javascript export function apiKeyMiddleware(req, res, next) { const apiKey = req.headers['x-api-key']; if (!apiKey || apiKey !== process.env.VALID_API_KEY) { return res.status(403).json({ message: 'Forbidden' }); } next(); } ``` And my API route looks like this: ```javascript import { apiKeyMiddleware } from '../../middleware/apiKey'; export default function handler(req, res) { const { query } = req; console.log('Query Params:', query); res.status(200).json({ message: 'Success', query }); } ``` Iām using Next.js version 12.1.0. When I make a request to this API route with parameters, for example `GET /api/data?type=user`, the console logs show that `query` is `undefined`. If I remove the middleware, the query parameters are logged correctly. I've tried debugging by adding console logs in both the middleware and route handler, and it's clear that after the middleware runs, the `req.query` object is not populated correctly. I've also checked that I'm sending the request with the required headers and parameters. Is there a known scenario with Next.js middleware affecting the request object, or am I missing something in my middleware implementation? Any ideas what could be causing this? I appreciate any insights!