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 proxy middleware service that transforms incoming API request paths before forwarding them to backend services. The service should handle multiple path transformation scenarios including removing prefixes, adding base paths, and rewriting versioned API endpoints.
Your service should create an Express application with three proxy middleware endpoints:
/api/v1http://localhost:4001/api/v1 prefix from incoming requests/legacy as a base path for the backendGET /api/v1/users → GET /legacy/users on backend/api/v2http://localhost:4002/api/v2 with /v2/servicesGET /api/v2/products → GET /v2/services/products on backend/adminhttp://localhost:4003X-User-Role: superadmin header, prepend /superadmin to the path/standard to the pathGET /admin/settings → GET /superadmin/settings on backendGET /admin/settings → GET /standard/settings on backend@test
// Mock backend server on port 4001
const backend = express();
backend.get('/legacy/users', (req, res) => res.json({ path: req.path }));
// Test request
const response = await request(app)
.get('/api/v1/users')
.expect(200);
expect(response.body.path).toBe('/legacy/users');@test
// Mock backend server on port 4002
const backend = express();
backend.get('/v2/services/products', (req, res) => res.json({ path: req.path }));
// Test request
const response = await request(app)
.get('/api/v2/products')
.expect(200);
expect(response.body.path).toBe('/v2/services/products');@test
// Mock backend server on port 4003
const backend = express();
backend.get('/superadmin/settings', (req, res) => res.json({ path: req.path }));
// Test request
const response = await request(app)
.get('/admin/settings')
.set('X-User-Role', 'superadmin')
.expect(200);
expect(response.body.path).toBe('/superadmin/settings');@test
// Mock backend server on port 4003
const backend = express();
backend.get('/standard/settings', (req, res) => res.json({ path: req.path }));
// Test request
const response = await request(app)
.get('/admin/settings')
.expect(200);
expect(response.body.path).toBe('/standard/settings');@generates
/**
* Creates and configures an Express application with proxy middleware endpoints
* that transform request paths before forwarding to backend services.
*
* @returns {Express.Application} Configured Express application
*/
function createProxyService() {
// Implementation here
}
module.exports = { createProxyService };Provides web server framework.
Provides proxy middleware with path transformation capabilities.
docs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10