A modern, type-safe CORS proxy service built from scratch with TypeScript and Node.js.
Live URL: https://cors.mani-coder.dev/
- Modern TypeScript with ESM modules
- Type-safe environment variable validation using Zod
- Request logging with timestamps and status indicators
- Fast development with
tsx(hot reload) - Code quality tools (Biome for linting & formatting)
- Testing setup with Vitest
- Production-ready deployment on Vercel
- Custom CORS proxy implementation (no external dependencies)
- Runtime: Node.js 24+
- Language: TypeScript 5.7
- Module System: ESM (ECMAScript Modules)
- Dev Tools: tsx, Biome, Vitest
- Deployment: Vercel
- Node.js >= 24.0.0
- npm, pnpm, or yarn
git clone https://github.com/mani-coder/cors-bypass.git
cd cors-bypassnpm installCopy the example environment file:
cp .env.example .envEdit .env with your configuration:
PORT=3000
NODE_ENV=development
ORIGIN_BLACKLIST=
ORIGIN_WHITELIST=
ALLOWED_PROXY_HOSTS=api.example.com,cdn.example.netnpm run devThe server will start on http://localhost:3000 with hot reload enabled.
| Command | Description |
|---|---|
npm run dev |
Start development server with hot reload |
npm run build |
Build for production |
npm start |
Run production build |
npm run type-check |
Type check without emitting files |
npm run lint |
Lint code with Biome |
npm run lint:fix |
Lint and auto-fix issues |
npm run format |
Format code with Biome |
npm test |
Run tests with Vitest |
npm run test:coverage |
Run tests with coverage report |
npm run clean |
Remove build directory |
| Variable | Description | Default | Required |
|---|---|---|---|
PORT |
Server port | 3000 |
No |
NODE_ENV |
Environment mode | development |
No |
ORIGIN_BLACKLIST |
Comma-separated list of blocked origins | "" |
No |
ORIGIN_WHITELIST |
Comma-separated list of allowed origins | "" |
No |
ALLOWED_PROXY_HOSTS |
Comma-separated list of allowed proxy hosts | "" |
No |
REQUIRE_HEADER |
Require Origin or X-Requested-With header (true/false) |
false |
No |
/ Shows help
/iscorsneeded Resource served without CORS headers
/<url> Proxy request to <url> with CORS headers
To proxy a request through the CORS bypass server:
const targetUrl = 'https://api.example.com/data';
const proxyUrl = 'https://cors.mani-coder.dev/';
fetch(proxyUrl + targetUrl)
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));- If the protocol is omitted, it defaults to
http(orhttpsif port 443 is specified) - Cookies are disabled and stripped from requests
- Redirects are automatically followed (up to 5 redirects)
- Each redirect adds a
X-CORS-Redirect-nheader for debugging - The requested URL is available in the
X-Request-URLresponse header - The final URL (after redirects) is in the
X-Final-URLresponse header
By default, the proxy allows all requests. You can enable header validation by setting REQUIRE_HEADER=true to require either the Origin or X-Requested-With header, which prevents casual browsing. Modern browsers automatically set these headers for fetch/AJAX requests.
For security, configure allowed hosts via the ALLOWED_PROXY_HOSTS environment variable:
ALLOWED_PROXY_HOSTS=api.example.com,cdn.example.net,data.example.orgRequests to any other hosts will be blocked with a 403 Forbidden response.
Control which origins can use your proxy:
# Only allow requests from these origins
ORIGIN_WHITELIST=https://myapp.com,https://myapp.dev
# Or block specific origins
ORIGIN_BLACKLIST=https://malicious-site.comcors-bypass/
├── src/
│ ├── index.ts # Main server file with request logging
│ ├── proxy.ts # Custom CORS proxy implementation
│ ├── env.ts # Environment validation with Zod
│ ├── env.test.ts # Environment tests
│ └── proxy.test.ts # Proxy tests
├── build/ # Compiled output (gitignored)
├── .nvmrc # Node.js version (24)
├── .node-version # Node.js version for various tools
├── biome.json # Biome configuration
├── tsconfig.json # TypeScript configuration
├── vitest.config.ts # Vitest configuration
├── vercel.json # Vercel deployment config
└── package.json # Project dependencies
This project uses Biome for linting and formatting, which is significantly faster than ESLint + Prettier.
# Check for issues
npm run lint
# Auto-fix issues
npm run lint:fix
# Format code
npm run formatTests are written using Vitest:
# Run tests
npm test
# Run tests with coverage
npm run test:coverageThe project uses strict TypeScript configuration with all safety checks enabled:
npm run type-checkAll incoming requests are automatically logged with detailed information:
[2025-12-30T05:03:48.150Z] ✓ GET 200 https://httpbin.org/status/200 (no-origin)
[2025-12-30T05:04:08.914Z] ✗ GET 404 https://httpbin.org/status/404 (no-origin)
[2025-12-30T05:04:15.736Z] ✓ GET 200 https://httpbin.org/get (origin=https://example.com)
Log Format:
- Timestamp: ISO 8601 format with milliseconds
- Status Indicator: ✓ (success 2xx), ✗ (error 4xx/5xx), • (redirect 3xx)
- Method: HTTP method (GET, POST, etc.)
- Status Code: HTTP response status
- Target URL: The proxied URL
- Origin: Request origin header (or "no-origin")
Benefits:
- Monitor usage patterns
- Debug proxy issues
- Track rate limiting from external APIs
- Identify abuse or unusual traffic
This project is configured for deployment on Vercel:
- Install Vercel CLI:
npm i -g vercel - Deploy:
vercel - Configure environment variables in Vercel dashboard
The build process will:
- Compile TypeScript to JavaScript (ESM)
- Output to
build/directory - Deploy using
@vercel/node
# Build
npm run build
# Start production server
npm start- Allowed Hosts: Always configure
ALLOWED_PROXY_HOSTSin production to prevent abuse - Rate Limiting: Consider implementing rate limiting for production use
- Origin Control: Use
ORIGIN_WHITELISTto restrict which domains can use your proxy - Request Logging: Built-in logging helps monitor usage patterns and detect abuse
- Monitoring: Review logs regularly to identify unusual traffic or potential attacks
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
ISC
Elayamani Krishnamoorthi - k.elayamani@gmail.com
- Live Service: https://cors.mani-coder.dev/
- GitHub: https://github.com/mani-coder/cors-bypass
- Issues: https://github.com/mani-coder/cors-bypass/issues