{"id":16385,"library":"http-proxy-rules","title":"HTTP Proxy Rules for Node-HTTP-Proxy","description":"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.","status":"abandoned","version":"1.1.3","language":"javascript","source_language":"en","source_url":"https://github.com/donasaur/http-proxy-rules","tags":["javascript","node-http-proxy","http-proxy","http-proxy-table","proxy-table","proxy-rules","proxy"],"install":[{"cmd":"npm install http-proxy-rules","lang":"bash","label":"npm"},{"cmd":"yarn add http-proxy-rules","lang":"bash","label":"yarn"},{"cmd":"pnpm add http-proxy-rules","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"This package is an add-on built specifically to work with node-http-proxy and requires it for core functionality.","package":"node-http-proxy","optional":false}],"imports":[{"note":"While CommonJS `require` is shown in examples, the library is old enough that it might predate widespread ESM usage. For modern projects using ESM, this is the correct pattern. Ensure your project is configured for CommonJS if using `require`.","wrong":"const HttpProxyRules = require('http-proxy-rules');","symbol":"HttpProxyRules","correct":"import HttpProxyRules from 'http-proxy-rules';"},{"note":"This package primarily exports a default class. Named imports like `{ HttpProxyRules }` will not work.","wrong":"import { HttpProxyRules } from 'http-proxy-rules';","symbol":"HttpProxyRules","correct":"const HttpProxyRules = require('http-proxy-rules');"}],"quickstart":{"code":"const http = require('http');\nconst httpProxy = require('http-proxy');\nconst HttpProxyRules = require('http-proxy-rules');\n\n// Set up proxy rules instance\nconst proxyRules = new HttpProxyRules({\n  rules: {\n    '.*/api/v1/users': 'http://localhost:3001/users',\n    '.*/api/v1/products/([0-9]+)': 'http://localhost:3002/items/$1',\n    '/admin': 'http://localhost:3003/dashboard',\n    '/images/(.*)': 'http://localhost:3004/assets/$1'\n  },\n  default: 'http://localhost:3000' // Default target if no rules match\n});\n\n// Create reverse proxy instance\nconst proxy = httpProxy.createProxy();\n\n// Create http server that leverages reverse proxy instance\n// and proxy rules to proxy requests to different targets\nhttp.createServer(function(req, res) {\n  const target = proxyRules.match(req);\n\n  if (target) {\n    console.log(`Proxying ${req.url} to ${target}`);\n    return proxy.web(req, res, { target: target });\n  } else {\n    console.log(`No rule matched for ${req.url}. Using default.`);\n    return proxy.web(req, res, { target: proxyRules.default });\n  }\n}).listen(6010, () => {\n  console.log('Proxy server listening on port 6010');\n  console.log('  - Try: http://localhost:6010/api/v1/users');\n  console.log('  - Try: http://localhost:6010/api/v1/products/123');\n  console.log('  - Try: http://localhost:6010/admin');\n  console.log('  - Try: http://localhost:6010/images/logo.png');\n  console.log('  - Try: http://localhost:6010/unknown-path');\n});","lang":"javascript","description":"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."},"warnings":[{"fix":"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.","message":"This package is explicitly an add-on to `node-http-proxy`. Updates or major version changes in `node-http-proxy` (e.g., v2.x to v3.x or later) may introduce incompatibilities that `http-proxy-rules` does not address, as it appears to be unmaintained. Developers should thoroughly test `http-proxy-rules` with newer `node-http-proxy` versions.","severity":"breaking","affected_versions":"All versions"},{"fix":"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/.*`.","message":"Rule matching order is crucial. If multiple rules could match a given URL path, the module will apply the *first* rule defined in the `rules` object. This relies on JavaScript engine behavior for object key enumeration, which has generally been insertion-order preserved since ES2015, but it's important to define rules from most specific to least specific.","severity":"gotcha","affected_versions":"All versions"},{"fix":"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`).","message":"The module automatically appends `(?:\\W|$)` to your regex-supported URL path keys. This means `.*/test` will match `/test`, `/test/`, or `/test?` but NOT `/testing`. Be mindful of this implicit suffix when crafting your rule keys, as it can lead to unexpected non-matches.","severity":"gotcha","affected_versions":"All versions"},{"fix":"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.","message":"The project appears to be abandoned, with no recent updates or maintenance activity on its GitHub repository. This means it may not receive security patches, bug fixes, or compatibility updates for newer Node.js versions or dependencies, making it a potential long-term risk for production systems.","severity":"deprecated","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"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.","cause":"This message indicates that the incoming HTTP request URL path did not match any of the regular expressions defined in the `rules` object of your `HttpProxyRules` instance, and no `default` target was specified or handled.","error":"The request url and path did not match any of the listed rules!"},{"fix":"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();`.","cause":"This error likely means that the `proxy` object, which is an instance of `node-http-proxy`, was not correctly initialized or imported. It could also happen if `node-http-proxy` itself failed to load.","error":"TypeError: proxy.web is not a function"}],"ecosystem":"npm"}