A minimal CLI helper to run a local development server with CORS enabled
npm install cors-dev-proxyA minimal CLI helper to run a local development server with CORS enabled. Perfect for frontend development when you need to proxy requests to a backend server that doesn't have CORS configured.
``bash`
npm install -g cors-dev-proxyor
pnpm add -g cors-dev-proxyor
yarn global add cors-dev-proxy
`bash`
cors-dev-proxy [options]
- -i, --in - Specify the port of the backend server to proxy to-o, --out
- - Specify the port for the CORS proxy (default: 3000)
Start a server and automatically detect its port:
`bash`
cors-dev-proxy npm run dev
Specify ports explicitly:
`bash`
cors-dev-proxy -i 5173 -o 3000 npm run dev
Run with Vite:
`bash`
cors-dev-proxy vite
Run with any command:
`bash`
cors-dev-proxy -o 8080 node server.js
1. Spawns your command - Runs the specified command (e.g., your dev server)
2. Detects the port - Automatically detects which port your server is listening on
3. Creates a CORS proxy - Starts a proxy server that forwards requests with proper CORS headers
4. Forwards requests - All requests to the proxy are forwarded to your backend with CORS enabled
- ✨ Automatic port detection - No need to specify ports if your server outputs them
- 🔄 WebSocket support - Proxies WebSocket connections too
- 🎯 Credentials support - Handles cookies and authorization headers
- 🚀 Zero configuration - Just wrap your existing dev command
- 📦 Minimal dependencies - Lightweight and fast
The proxy automatically adds:
- Access-Control-Allow-Origin - Set to the request origin or *Access-Control-Allow-Methods
- - Supports GET, POST, PUT, DELETE, OPTIONSAccess-Control-Allow-Headers
- - Allows all requested headersAccess-Control-Allow-Credentials` - Enabled when cookies/auth are present
-
MIT © Viktor Lázár