har-proxy
v1.0.5
Published
A CLI tool that parses HAR files and creates a RESTful mock server
Readme
HAR Proxy
A CLI tool that parses HAR (HTTP Archive) files and creates a RESTful mock server. Perfect for API mocking, testing, and development without backend dependencies.
Installation
# Using npm
npm install -g har-proxy
# Using pnpm
pnpm add -g har-proxy
# Or run directly with npx
npx har-proxy <har-file>Requirements
- Node.js >= 18.0.0
Usage
har-proxy <har-file> [options]Options
| Option | Description | Default |
|--------|-------------|---------|
| -p, --port <number> | Port to run the server on | 3000 |
| --no-cors | Disable automatic CORS header injection | CORS enabled |
| -V, --version | Output the version number | - |
| -h, --help | Display help information | - |
Examples
# Start server with default port (3000)
har-proxy recording.har
# Start server on custom port
har-proxy recording.har --port 8080
har-proxy recording.har -p 8080
# Disable automatic CORS headers (use original HAR CORS headers)
har-proxy recording.har --no-corsCORS Support
By default, har-proxy automatically adds CORS headers to all responses, allowing cross-origin requests from any domain:
Access-Control-Allow-Origin: *Access-Control-Allow-Methods: GET, POST, PUT, DELETE, PATCH, OPTIONSAccess-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With
The server also handles preflight OPTIONS requests automatically.
Note: If your HAR file already contains CORS headers, har-proxy will preserve them and not add duplicates.
Disabling CORS
Use --no-cors when:
- You need to test CORS behavior with specific origins
- Your frontend handles CORS differently
har-proxy recording.har --no-corsWhen CORS is disabled, any CORS headers present in the original HAR recording will be preserved.
Important: Proxy Path
All HAR-recorded endpoints are served under the /proxy path prefix.
For example, if your HAR file contains a request to /api/users, it will be available at:
http://localhost:3000/proxy/api/usersThis design separates HAR endpoints from internal routes (dashboard, health checks, etc.).
Path Mapping Examples
| Original HAR Path | Proxy Server Path |
|-------------------|-------------------|
| /api/users | /proxy/api/users |
| /api/products/123 | /proxy/api/products/123 |
| /v1/auth/login | /proxy/v1/auth/login |
Query Parameters
Query parameters in requests are automatically stripped for matching purposes. This means:
# Both of these will match the same HAR entry for GET /api/users
curl http://localhost:3000/proxy/api/users
curl http://localhost:3000/proxy/api/users?page=1&limit=10This allows flexible testing without needing exact query parameter matches.
Dashboard
After starting the server, a web dashboard is available at the root path:
http://localhost:3000/The dashboard displays all loaded endpoints grouped by base path, showing:
- HTTP method (GET, POST, PUT, DELETE, PATCH)
- Full endpoint path
- Response status code
- Content type

Quick Start Example
Export a HAR file from your browser's DevTools (Network tab → Right-click → Save all as HAR)
Start the proxy server:
har-proxy my-api-recording.har -p 3000Output:
Loading HAR file: /path/to/my-api-recording.har 🚀 HAR Proxy server running at http://localhost:3000 📊 Dashboard available at http://localhost:3000/ 📦 Loaded 15 endpoints 🌐 CORS: enabled (default) Press Ctrl+C to stop the serverAccess your mocked endpoints:
# If HAR contained GET /api/users curl http://localhost:3000/proxy/api/users
How It Works
- Parse: Reads and parses the HAR file to extract HTTP request/response pairs
- Map: Creates an endpoint map where later entries override earlier ones (latest wins)
- Serve: Starts an HTTP server that matches incoming requests to recorded responses
- Dashboard: Generates an HTML dashboard for easy endpoint discovery
Use Cases
- Frontend Development: Mock backend APIs during UI development
- Testing: Create reproducible test environments with recorded responses
- Demos: Showcase applications without live backend dependencies
- Debugging: Replay specific API scenarios for troubleshooting
License
ISC
