A lightweight reverse proxy built using Node.js, Express, and MongoDB, featuring:
✅ Route-based proxying 📄 Request logging to MongoDB 🔒 IP-based rate limiting 📈 Health and Prometheus-style metrics endpoints 🛠 Minimal dependencies, no heavy frameworks
├── db/
│ └── mongoClient.js # MongoDB connection + collection handler
├── middleware/
│ ├── rateLimiter.js # Rate limiting logic (express-rate-limit)
│ └── requestLogger.js # Logs requests to MongoDB
├── proxy/
│ ├── routeConfig.js # Maps prefixes to backend services
│ └── router.js # Handles proxying logic using native http
├── mock-service1.js # Mock service on port 4000 (for testing)
├── mock-service2.js # Mock service on port 5000 (for testing)
├── server.js # Main app entry point
├── .env # Environment config
├── package.json
└── README.md
Routes incoming requests based on prefix:
| Proxy Path | Target Backend |
|---|---|
| /api/service1/* | http://localhost:4000 |
| /api/service2/* | http://localhost:5000 |
Every request is logged with:
- Method, URL, headers
- Status code and response time
- Timestamp
Stored in: proxyLogs.requests collection
Limits each IP to 30 requests per minute using express-rate-limit.
After exceeding:
{
"status": 429,
"error": "Too many requests, please try again later."
}GET /health
Returns app and DB status, uptime, memory usage:
{
"status": "ok",
"db": "connected",
"uptime": "123s",
"memory": 34506752,
"version": "1.0.0",
"hostname": "localhost"
}GET /metrics
Returns Prometheus-compatible plain text metrics like:
# HELP app_uptime_seconds Uptime in seconds
app_uptime_seconds 123.45
# HELP app_memory_rss_bytes Resident memory usage
app_memory_rss_bytes 34506752
Use Postman or curl:
GET http://localhost:3000/api/service1/hello→ "Hello from Service 1"GET http://localhost:3000/api/service2/hello→ "Hello from Service 2"
for i in {1..12}; do
curl -s -o /dev/null -w "%{http_code}\n" http://localhost:3000/api/service1/hello
doneLast 2 requests should return 429.
git clone <your-repo-url>
cd reverse-proxy
npm installPORT=3000
MONGO_URI=mongodb+srv://<user>:<password>@<cluster-url>/reverseProxynpm startAlso start the mock services:
node mock-service1.js
node mock-service2.js- JWT/Auth support
- Redis-based rate limiting
- HTTPS & TLS termination
- Admin UI to view logs
- Load balancing between targets