79801450

Date: 2025-10-27 04:45:53
Score: 2
Natty:
Report link

please provide more context on your requirements.

in fact, you can try wrapping your nextjs request with the wrapper function. something similar to this:

import { performance } from 'perf_hooks';
import { getLogger } from 'Utils/logger';

export const withSlowRequestLogging = (handler) => {
  return async function (request, response) {
    const threshold = 1000;

    const start = performance.now();
    let logged = false;

    const logSlowRequestEvent = () => {
      if (logged) return;
      logged = true;

      const duration = performance.now() - start;

      if (duration > threshold) {
        setImmediate(() => logSlowRequest(request, response, duration, threshold));
      }
    };

    response.once('finish', logSlowRequestEvent);
    response.once('close', logSlowRequestEvent);
    response.once('error', logSlowRequestEvent);

    return handler(request, response);
  };
}

const logSlowRequest = (req, res, durationMs, thresholdMs) => {
  // Log information here
}

Vercel Functions using the Edge runtime must begin sending a response within 25 seconds to maintain streaming capabilities beyond this period, and can continue streaming data for up to 300 seconds.

The edge runtime configured is neither a Node.js nor browser application, which means it doesn't have access to all browser and Node.js APIs, so it is impossible to add logger to the middleware. Vercel has a great Edge Runtime self-explanatory docs for more context and info.

Reasons:
  • RegEx Blacklisted phrase (2.5): please provide
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Aleksandrs