Route API calls from a React or Next.js frontend through a local proxy to avoid browser CORS errors during development.
Rewrite URL paths before forwarding, map /api/v1 on your server to a different path on the target service.
Forward WebSocket connections through the same proxy middleware alongside regular HTTP requests.
Bundle reusable proxy configuration as a named plugin to apply consistent routing across multiple server setups.
http-proxy-middleware is a Node.js library that lets you forward incoming HTTP requests from your server to a different server. This is commonly needed when building web applications where the frontend and backend run on separate addresses, and you want the frontend to be able to make requests without hitting browser security restrictions that block cross-origin requests. The library is designed to work as middleware, meaning you plug it into an existing server framework rather than running it standalone. It works with popular Node.js server tools including Express, Connect, Next.js, and Hono, among others. Setting it up is typically a single function call where you specify the destination server address. Once configured, incoming requests that match a path you specify get forwarded to the target server. The library gives you options to filter which requests get proxied using path strings, wildcard patterns, or a custom function. You can also rewrite the URL path before forwarding, so for example a request coming in at /api/users could be sent to /v2/users on the target server. For more advanced use cases, the library allows you to intercept and modify both requests before they are forwarded and responses before they are returned to the original caller. It also supports WebSocket connections, not just regular HTTP. A plugin system lets you bundle reusable configuration as named plugins. The package is available on npm and the source code is written in TypeScript, so type definitions are included. It relies on an underlying proxy library called httpxy, which is a maintained fork of the older http-proxy package. The project has a test suite and documentation with working examples for common scenarios. It is released under the MIT License.
← chimurai on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.