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

API Request Router

Build a middleware-based request router that selectively forwards API requests to different backend services based on URL patterns.

Requirements

Your task is to create an Express server that acts as a gateway, forwarding specific API requests to a backend service while letting other requests pass through normally.

The server should:

  1. Forward requests matching /api/users/** to a backend service at http://localhost:4000
  2. Forward requests matching /api/data/*.json to the same backend service
  3. Not forward requests to /api/users/health (this should be excluded from proxying)
  4. Change the origin header to match the target server
  5. Log basic information about proxied requests (method and path)

All other requests (not matching the patterns above) should return a 404 response with the message "Not Found".

Test Cases

  • GET request to /api/users/123 is forwarded to the backend @test
  • GET request to /api/data/report.json is forwarded to the backend @test
  • GET request to /api/users/health is not forwarded and returns 404 @test
  • GET request to /other is not forwarded and returns 404 @test

Implementation

@generates

API

/**
 * Creates and returns an Express application configured with proxy middleware.
 * The app should be ready to listen on a port.
 *
 * @returns {Express.Application} Configured Express application
 */
function createApp() {
  // Implementation
}

module.exports = { createApp };

Dependencies { .dependencies }

express { .dependency }

Provides web server framework.

@satisfied-by

http-proxy-middleware { .dependency }

Provides proxy middleware functionality.

@satisfied-by

tile.json