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 Node.js API gateway service that routes incoming requests to different backend servers based on tenant information extracted from request headers. The gateway should support multiple routing strategies and handle both synchronous and asynchronous tenant lookups.
Your implementation should:
X-Tenant-ID request headertenant-a → http://localhost:4001tenant-b → http://localhost:4002tenant-c → http://localhost:4003For tenant IDs not in the static mapping, simulate a database lookup that:
http://localhost:4004 for valid tenantsnull for invalid tenant IDs (e.g., tenant IDs that start with "invalid-")The following test cases should pass:
X-Tenant-ID: tenant-a, the proxy routes to http://localhost:4001 @testX-Tenant-ID: tenant-unknown, the proxy performs async lookup and routes to http://localhost:4004 @testX-Tenant-ID: invalid-tenant, the proxy returns 404 status @testX-Tenant-ID header, the proxy returns 404 status @test@generates
/**
* Simulates async database lookup for tenant configuration
* @param {string} tenantId - The tenant identifier
* @returns {Promise<string|null>} Backend URL or null if tenant is invalid
*/
async function lookupTenantBackend(tenantId) {
// IMPLEMENTATION HERE
}
/**
* Creates and configures the Express app with proxy middleware
* @returns {Express} Configured Express application
*/
function createApp() {
// IMPLEMENTATION HERE
}
module.exports = { createApp, lookupTenantBackend };Provides HTTP proxy middleware functionality with dynamic routing support.
Provides web server framework for handling HTTP requests.
docs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10