The one-liner node.js proxy middleware for connect, express, next.js and more
92
Pending
Does it follow best practices?
Impact
92%
1.24xAverage score across 10 eval scenarios
Pending
The risk profile of this skill
Build a simple API gateway service that routes requests to different backend services based on tenant information and request path patterns.
Your gateway should support the following routing logic:
Tenant-based routing: Route requests based on a tenant subdomain in the Host header
Host: acme.localhost:3000 should route to http://localhost:8001Host: globex.localhost:3000 should route to http://localhost:8002Host: initech.localhost:3000 should route to http://localhost:8003Path-based fallback routing: For requests without a recognized tenant subdomain, route based on the path
/api/v1/* should route to http://localhost:8001/api/v2/* should route to http://localhost:8002http://localhost:9000 (default backend)Combined routing: Support tenant+path combinations that take precedence over tenant-only matches
Host: acme.localhost:3000 and path /legacy/* should route to http://localhost:7000@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.
/**
* Express application configured with proxy middleware that routes
* requests to different backend services based on tenant and path.
*/
export default app;acme.localhost:3000/api/users route to http://localhost:8001 @testglobex.localhost:3000/data route to http://localhost:8002 @testinitech.localhost:3000/products route to http://localhost:8003 @testlocalhost:3000/api/v1/users (no tenant subdomain) route to http://localhost:8001 @testlocalhost:3000/api/v2/data (no tenant subdomain) route to http://localhost:8002 @testlocalhost:3000/public/index.html (no tenant, unmatched path) route to http://localhost:9000 @testacme.localhost:3000/legacy/api route to http://localhost:7000 (tenant+path combination) @testProvides HTTP proxy middleware functionality with dynamic routing capabilities.
@satisfied-by
docs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10