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

API Gateway Proxy Server

Build a simple API gateway server that forwards incoming requests to different backend services based on the request path.

Requirements

Your server should:

  1. Listen on port 3000
  2. Forward requests starting with /api/users to http://localhost:4001
  3. Forward requests starting with /api/products to http://localhost:4002
  4. Change the origin header to match the target server for compatibility with virtual hosted sites
  5. Return appropriate error responses when the backend service is unavailable

Implementation Details

  • Use Express.js as the web framework
  • The server should handle both HTTP and HTTPS requests to the backend
  • Ensure proper error handling for connection failures

Dependencies { .dependencies }

express { .dependency }

Provides web server framework.

http-proxy-middleware { .dependency }

Provides HTTP/HTTPS proxy middleware functionality.

Test Cases

Test 1: User API Forwarding { .test @test }

File: src/server.test.js

Test: When a GET request is made to /api/users/123, it should be forwarded to http://localhost:4001/api/users/123.

Setup: Start a mock backend server on port 4001 that responds with {"service": "users"} for any request.

Expected: The response should be {"service": "users"} with status code 200.

Test 2: Product API Forwarding { .test @test }

File: src/server.test.js

Test: When a GET request is made to /api/products/456, it should be forwarded to http://localhost:4002/api/products/456.

Setup: Start a mock backend server on port 4002 that responds with {"service": "products"} for any request.

Expected: The response should be {"service": "products"} with status code 200.

Test 3: Error Handling { .test @test }

File: src/server.test.js

Test: When a GET request is made to /api/users/123 but the backend service is not running, it should return an error response.

Setup: Ensure no server is running on port 4001.

Expected: The response should have a 5xx status code (500, 502, or 504).

tile.json