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

Express Proxy with Body Parser Integration

Build a simple Express-based API proxy server that forwards POST requests to a backend service while properly handling request bodies that have been parsed by body-parser middleware.

Problem Context

Many Express applications use body-parser middleware to parse incoming request bodies for easy access in route handlers. However, when you want to proxy these requests to a backend service, the request stream has already been consumed by body-parser, which can cause issues. Your task is to build a proxy server that correctly handles this scenario.

Requirements

Your server should:

  1. Accept POST requests on /api/data endpoint with JSON payloads
  2. Accept POST requests on /api/form endpoint with URL-encoded form data
  3. Parse request bodies using appropriate body-parser middleware before proxying
  4. Forward these requests to a target backend server, reconstructing the request body properly
  5. Return the backend's response to the client

Implementation

@generates

API

/**
 * Express server that proxies POST requests to a backend service.
 * The server should listen on port 3000.
 *
 * Routes:
 * - POST /api/data - Accepts JSON payloads, proxies to backend
 * - POST /api/form - Accepts URL-encoded form data, proxies to backend
 */

Test Cases

  • Server accepts JSON POST request to /api/data with {"name": "test", "value": 123} and forwards it to the backend @test
  • Server accepts form POST request to /api/form with field1=value1&field2=value2 and forwards it to the backend @test
  • Backend receives properly formatted request body with correct Content-Type headers @test

Dependencies { .dependencies }

http-proxy-middleware { .dependency }

Provides proxy middleware functionality for Express, including request body reconstruction.

express { .dependency }

Web application framework for Node.js.

body-parser { .dependency }

Middleware to parse request bodies in Express applications.

tile.json