CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-http-proxy-middleware

The one-liner node.js proxy middleware for connect, express, next.js and more

92

1.24x
Quality

Pending

Does it follow best practices?

Impact

92%

1.24x

Average score across 10 eval scenarios

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

task.mdevals/scenario-3/

Proxy Request Monitor

A middleware-based request monitoring and metrics system that tracks proxy operations and provides real-time statistics.

@generates

Requirements

Implement a proxy monitoring system that extends the capabilities of an HTTP proxy middleware to collect and expose metrics about proxy operations. The system should provide real-time visibility into proxy performance and error patterns.

Core Functionality

The system must implement a middleware that:

  1. Tracks the total number of proxied requests
  2. Records response times for each request (time between when the proxy receives the request and when it receives the response from the target)
  3. Counts successful responses (status codes < 400) and error responses (status codes >= 400)
  4. Logs proxy errors with timestamp, URL, and error message
  5. Calculates average response time across all tracked requests
  6. Provides a method to retrieve current metrics as a JavaScript object

Metrics Structure

The metrics object returned should have the following structure:

{
  requests: <number>,           // Total proxied requests
  responses: {
    success: <number>,          // Responses with status < 400
    error: <number>             // Responses with status >= 400
  },
  responseTime: <array>,        // Array of response times in milliseconds
  errors: <array>,              // Array of error objects with timestamp, url, and error message
  averageResponseTime: <number> // Average of all response times
}

Implementation Details

  • The system should maintain a maximum of 1000 response times (keeping only the most recent)
  • The system should maintain a maximum of 100 error records (keeping only the most recent)
  • Response times should be measured in milliseconds
  • Error timestamps should be in ISO 8601 format

Test Cases

  • Creating a proxy with monitoring plugin and making a successful request increments the request counter @test
  • Successful responses (status code 200) are counted in the success metrics @test
  • Error responses (status code 500) are counted in the error metrics @test
  • Average response time is correctly calculated from tracked response times @test

API

/**
 * Creates a monitoring plugin for the proxy middleware that tracks
 * requests, responses, and errors
 *
 * @param {Object} proxyServer - The http-proxy server instance
 * @param {Object} options - The proxy middleware options
 */
function createMonitoringPlugin(proxyServer, options) {
  // Plugin implementation
}

/**
 * Gets the current metrics collected by the monitoring plugin
 *
 * @returns {Object} Metrics object containing request counts, response times, and errors
 */
function getMetrics() {
  // Returns metrics object
}

module.exports = {
  createMonitoringPlugin,
  getMetrics
};

Dependencies { .dependencies }

http-proxy-middleware { .dependency }

Provides proxy middleware functionality with plugin support.

@satisfied-by

tile.json