adaptive-gateway
v1.0.5
Published
Adaptive Express gateway middleware with caching, circuit breaker fallback, and rate limiting.
Maintainers
Readme
Adaptive Gateway
adaptive-gateway is a lightweight Express-compatible gateway middleware with caching, circuit-breaker fallback, and rate limiting.
Install
npm install adaptive-gatewayUsage
import express from 'express';
import gateKeep from 'adaptive-gateway';
const app = express();
app.use(express.json());
app.use('/proxy', gateKeep({
target: 'http://localhost:3000',
ttl: 300,
latencyThreshold: 500,
pathRewrite: path => path.replace(/^\/proxy/, ''),
breakerOptions: {
timeout: 8000,
errorThresholdPercentage: 50,
resetTimeout: 10000
}
}));
app.listen(4000, () => {
console.log('Gateway running on http://localhost:4000');
});Named exports
import { adaptiveGateway, createGateKeepMiddleware, gateKeep } from 'adaptive-gateway';adaptiveGateway(options)— gateway wrapper with built-in rate limitingcreateGateKeepMiddleware(options)— reusable middleware factorygateKeep— alias forcreateGateKeepMiddleware
Options
target— backend URL to proxy tottl— cache TTL in secondslatencyThreshold— threshold for request caching decisionspathRewrite— function to rewrite the incoming request path before proxyingbreakerOptions— opossum circuit breaker configuration
Notes
This package is designed to be used in an Express app and assumes a Redis client and metrics pipeline are configured in the local project.
