http-proxy-rules is an add-on module designed to work with the `node-http-proxy` library, providing a mechanism to define and manage routing rules for a reverse proxy. It allows developers to configure a set of regular expression-based URL path matching rules that translate incoming client requests to different target URLs for the backend service. The current stable version is 1.1.3. As of current observations, the package appears to be unmaintained, with no recent releases or active development, suggesting a very slow or non-existent release cadence. Its primary differentiator is its simple, regex-based rule matching system built specifically to integrate with `node-http-proxy`, providing a more structured way to handle complex routing logic compared to manual request inspection within the proxy server. It prioritizes the first matching rule based on object key order.
npm install http-proxy-rulesVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to set up an HTTP proxy server using `http-proxy-rules` to define routing logic and `node-http-proxy` to handle the actual proxying. It creates a proxy server on port 6010 that routes requests based on URL path patterns to different target backend services, with a default fallback. This shows how to initialize `HttpProxyRules`, define regex-based rules, and use the `match` method within an `http-proxy` server callback.
Review the changelogs for `node-http-proxy` and `http-proxy-rules` carefully. Consider migrating to more actively maintained proxy solutions if encountering issues with newer Node.js or `node-http-proxy` versions.
Structure your `rules` object such that more specific or exact matches appear earlier in the object definition than broader, more general matches. For example, a rule for `/users/profile` should come before a rule for `/users/.*`.
Test your rules thoroughly with various URL paths, including those you expect to match and those you expect *not* to match. If you need a more permissive match that includes suffixes, you may need to adjust your regex (e.g., `.*/test.*` if you truly want to match `/testing`).
For new projects, consider using actively maintained alternatives for HTTP proxying and routing. For existing projects, evaluate the risk, ensure thorough testing, and consider contributing fixes or migrating if vulnerabilities or critical bugs arise.
Ensure that your `rules` object contains a regex that correctly captures the URL path you are attempting to proxy. Test your regex patterns using an online regex tester. Also, consider adding a `default` target to your `HttpProxyRules` configuration to handle un-matched requests gracefully.
Verify that `node-http-proxy` is correctly installed (`npm install http-proxy`) and that `httpProxy.createProxy()` is called correctly to create the proxy instance: `var proxy = httpProxy.createProxy();`.