koa-proxy is an unmaintained proxy middleware specifically designed for Koa 2.x applications. It allows developers to proxy HTTP requests to a different host or URL, offering features like path mapping, regular expression-based matching for selective proxying, and control over request/response headers and cookie forwarding. Given its `1.0.0-alpha.3` version and last update several years ago, it is considered abandoned. This package predates modern JavaScript features like `async/await` and ESM, focusing on a synchronous middleware pattern and CommonJS module system. Its core functionality enables simple URL redirection and content serving from external sources within a Koa server.
npm install koa-proxyVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic usage of koa-proxy to forward requests, including path matching, URL remapping, and header/cookie forwarding options.
Migrate to a actively maintained Koa proxy middleware like `koa-proxies`, `@koa/proxy`, or `http-proxy-middleware` (if used with `koa-connect`).
If migrating, ensure your Koa application is also on a compatible version (Koa 2.x) or use a modern proxy solution designed for current Koa versions.
Thoroughly test `match` regex patterns. Use online regex testers to validate behavior before deployment. For example, `match: /^\/api\//` proxies `/api/foo` but not `/foo/api`.
Enable cookie forwarding by setting the `jar` option to `true` in the proxy configuration: `app.use(proxy({ host: '...', jar: true }));`Be explicit with header names, or test thoroughly to ensure the correct headers are suppressed without unintended side effects. For example, `['authorization', 'cookie']`.
Ensure you are using Koa 2.x or later and have initialized `app = new Koa();` correctly. This error can also occur if `koa` is not properly installed or required.
Carefully review and test your `match` regex and `map` function. Use console logs within the `map` function to see the `path` argument and its return value. Verify the regex logic with an online tool.
Set `jar: true` in your proxy configuration to enable forwarding of client cookies to the target host: `app.use(proxy({ host: '...', jar: true }));`Check your `suppressResponseHeaders` array and ensure it does not include headers you intend to pass through. Remember that matching is case-insensitive.