Package Exports
- simple-proxy-id
- simple-proxy-id/src/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (simple-proxy-id) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
simple-proxy-id
๐ A secure HTTP/HTTPS proxy for Node.js with zero dependencies and fixed target. Think of it as a safe reverse proxy that prevents open proxy abuse.
โจ Features
- Standalone HTTP/HTTPS proxy server.
- Express middleware for proxy.
- Fixed target (secure by default, cannot be changed from requests).
- Optional
changeOriginto set Host header. - Automatic error handling.
- Logger plugin with daily rotating logs.
- IP detection (Cloudflare Tunnel compatible).
- TypeScript definitions included.
- Zero dependencies.
๐ฆ Installation
npm install simple-proxy-id๐ Usage
Basic Usage (Standalone)
const { createProxy } = require('simple-proxy-id');
// Create proxy server
const server = createProxy({
target: 'https://jsonplaceholder.typicode.com',
changeOrigin: true,
port: 3000
});
// Access: http://localhost:3000/postsExpress Middleware
const express = require('express');
const { createProxyMiddleware } = require('simple-proxy-id');
const app = express();
// Proxy for path /api/*
app.use('/api', createProxyMiddleware({
target: 'https://jsonplaceholder.typicode.com',
changeOrigin: true
}));
app.listen(3000);
// Access: http://localhost:3000/api/postsWith Logger Plugin
const express = require('express');
const { createProxyMiddleware } = require('simple-proxy-id');
const createLogger = require('simple-proxy-id/src/plugins/logger');
const app = express();
// Enable request logging
app.use(createLogger({
logDir: './logs',
maxDays: 7
}));
app.use('/api', createProxyMiddleware({
target: 'https://jsonplaceholder.typicode.com',
changeOrigin: true
}));
app.listen(3000);๐งช Testing
npm testJest is used for testing. All tests must pass before publishing.
๐ Project Structure
src/ โ main source code
plugins/ โ logger plugin
test/ โ jest test suite
example/ โ usage examples๐ API
createProxy(options)
Create a standalone HTTP/HTTPS proxy server.
Parameters:
target(string, required): Target URL to proxychangeOrigin(boolean, optional): Set Host header to target (default: false)port(number, optional): Port for proxy server (default: 3000)
Returns: http.Server instance
Example:
const server = createProxy({
target: 'https://api.example.com',
changeOrigin: true,
port: 8080
});createProxyMiddleware(options)
Create Express middleware for proxy.
Parameters:
target(string, required): Target URL to proxychangeOrigin(boolean, optional): Set Host header to target (default: false)
Returns: Express middleware function
Example:
app.use('/api', createProxyMiddleware({
target: 'https://api.github.com',
changeOrigin: true
}));createLogger(options)
Create logger middleware for tracking requests.
Parameters:
logDir(string, optional): Directory to store log files (default: './logs')maxDays(number, optional): Days to keep logs before auto-cleanup (default: 7)
Returns: Express/Connect middleware function
Example:
const createLogger = require('simple-proxy-id/src/plugins/logger');
app.use(createLogger({
logDir: './logs',
maxDays: 14
}));Log Format:
[2025-10-02 14:30:45] 192.168.1.100 GET /api/users 200 125msFeatures:
- Daily rotating log files (YYYY-MM-DD.log)
- Captures real IP (supports Cloudflare Tunnel)
- Automatic cleanup of old logs
- Zero dependencies
๐ Security
This library is designed with security-first principles:
The proxy target is fixed in code and cannot be changed by external requests.
| Attack Vector | Protected |
|---|---|
| Request headers manipulation | โ |
| Query string injection | โ |
| Request body tampering | โ |
| Open proxy abuse | โ |
IP Detection Priority (Logger Plugin):
When logging requests, the logger detects the real client IP in this order:
CF-Connecting-IPheader (Cloudflare Tunnel)X-Forwarded-Forheader (Proxy/Load Balancer)X-Real-IPheader (Nginx proxy)socket.remoteAddress(Direct connection)
๐ License
MIT ยฉ 2025