Middleware for Unique Identifiers per request and Compression of response in Next.js API Routes

Viewed 28

I'm building API routes using Next.js to send a image and text-file as response. In the Next.js documentation I can find middleware for use cases like redirection and cookies.

I have use-case where:

  1. I need to generate a unique-identifier for each request I'm receiving and add that in output of logs generated by Pino.
  2. Compress the Image and text-file I'm sending as response.

How can it be done using middlewares?

0 Answers
Related