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

Multi-Tenant API Gateway

Build a simple API gateway service that routes requests to different backend services based on tenant information and request path patterns.

Requirements

Your gateway should support the following routing logic:

  1. Tenant-based routing: Route requests based on a tenant subdomain in the Host header

    • Requests with Host: acme.localhost:3000 should route to http://localhost:8001
    • Requests with Host: globex.localhost:3000 should route to http://localhost:8002
    • Requests with Host: initech.localhost:3000 should route to http://localhost:8003
  2. Path-based fallback routing: For requests without a recognized tenant subdomain, route based on the path

    • Requests to /api/v1/* should route to http://localhost:8001
    • Requests to /api/v2/* should route to http://localhost:8002
    • All other requests should route to http://localhost:9000 (default backend)
  3. Combined routing: Support tenant+path combinations that take precedence over tenant-only matches

    • Requests with Host: acme.localhost:3000 and path /legacy/* should route to http://localhost:7000

Implementation

@generates

Create an Express server on port 3000 that implements the routing logic described above using proxy middleware. The server should route requests to appropriate backend targets and ensure the Origin header matches the target server.

API

/**
 * Express application configured with proxy middleware that routes
 * requests to different backend services based on tenant and path.
 */
export default app;

Test Cases

  • Requests to acme.localhost:3000/api/users route to http://localhost:8001 @test
  • Requests to globex.localhost:3000/data route to http://localhost:8002 @test
  • Requests to initech.localhost:3000/products route to http://localhost:8003 @test
  • Requests to localhost:3000/api/v1/users (no tenant subdomain) route to http://localhost:8001 @test
  • Requests to localhost:3000/api/v2/data (no tenant subdomain) route to http://localhost:8002 @test
  • Requests to localhost:3000/public/index.html (no tenant, unmatched path) route to http://localhost:9000 @test
  • Requests to acme.localhost:3000/legacy/api route to http://localhost:7000 (tenant+path combination) @test

Dependencies { .dependencies }

http-proxy-middleware { .dependency }

Provides HTTP proxy middleware functionality with dynamic routing capabilities.

@satisfied-by

tile.json