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-9/

WebSocket Chat Proxy Server

Build a proxy server that forwards HTTP and WebSocket traffic to multiple backend services with external WebSocket upgrade handling and comprehensive event monitoring.

Requirements

Create a proxy server that:

  1. Handles HTTP requests - Forward API requests to a backend REST service
  2. Proxies WebSocket connections - Forward WebSocket connections to a separate chat backend service
  3. External upgrade handling - Manually handle the WebSocket upgrade event (do not rely on automatic subscription)
  4. Monitors WebSocket lifecycle - Log when WebSocket connections open and close
  5. Tracks connection data - Log data flowing through WebSocket connections for debugging purposes
  6. Modifies upgrade requests - Add a custom header X-Forwarded-For to WebSocket upgrade requests before forwarding

Server Configuration

  • HTTP proxy target: http://localhost:4000
  • WebSocket proxy target: ws://localhost:4001
  • Server listens on port: 3000
  • API requests to /api/* should be forwarded via HTTP
  • WebSocket connections to /chat should be forwarded via WebSocket

Implementation

@generates

API

/**
 * Creates and starts a proxy server that handles both HTTP and WebSocket traffic.
 * Returns the server instance for testing purposes.
 *
 * @returns {http.Server} The HTTP server instance
 */
function startProxyServer();

Test Cases

  • Server starts successfully on port 3000 @test
  • HTTP requests to /api/users are proxied to http://localhost:4000/api/users @test
  • WebSocket connections to /chat are proxied to ws://localhost:4001/chat @test
  • WebSocket upgrade requests include X-Forwarded-For header @test

Dependencies { .dependencies }

http-proxy-middleware { .dependency }

Provides proxy middleware functionality for HTTP and WebSocket connections with lifecycle event handling.

@satisfied-by

express { .dependency }

Provides web server framework for handling HTTP requests.

@satisfied-by

tile.json