Registry / web-framework / koa2-proxy-middleware

koa2-proxy-middleware

JSON →
library0.0.4jsnpmunverified

A Koa2 middleware wrapping http-proxy-middleware to proxy requests based on URL patterns using path-to-regexp. Version 0.0.4 is the current stable release; the package is infrequently updated. It provides a declarative way to configure multiple proxy targets in Koa2 applications, leveraging the mature http-proxy-middleware for WebSocket and HTTP proxying. Unlike generic Koa proxy middlewares, it uses path-to-regexp for route matching, allowing dynamic route parameters. It ships TypeScript definitions.

npm install koa2-proxy-middleware
INSTALL
IMPORT
SIG · KOA2-PROXY-MIDDLEW
K
koa2-proxy-middleware
web-frameworkjavascriptv0.0.4
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
const proxy = require('koa2-proxy-middleware')
import proxy from 'koa2-proxy-middleware'
Package uses CommonJS; default export is a function. For TypeScript, use `import proxy = require('koa2-proxy-middleware')` or `import * as proxy from 'koa2-proxy-middleware'`.
default
import proxy from 'koa2-proxy-middleware'
If using ESM with moduleResolution node or bundler, default import works in TypeScript.
ProxyMiddleware
import { ProxyMiddleware } from 'koa2-proxy-middleware'
TypeScript type export for the proxy function signature used in type annotations.

Creates a Koa server that proxies all requests matching '/api/(.*)' to httpbin.org using the proxy middleware.

const Koa = require('koa'); const proxy = require('koa2-proxy-middleware'); const app = new Koa(); const options = { targets: { '/api/(.*)': { target: 'http://httpbin.org', changeOrigin: true, }, }, }; app.use(proxy(options)); app.listen(3000); console.log('Proxy server running on port 3000');
Debug
Known issues
breakingPackage is CommonJS-only; cannot be imported as ESM in Node.js without bundler.
fix
Use require() or configure module resolution to allow CommonJS.
affects: >=0.0.0
gotchaBodyparser middleware must be placed after proxy middleware for POST requests to avoid delays.
fix
Ensure proxy middleware is used before koa-bodyparser or similar body parsers.
affects: >=0.0.0
deprecatedpath-to-regexp v2 used internally; newer versions may have breaking changes.
fix
No action needed unless you rely on specific regexp behavior.
affects: >=0.0.0
gotchaOptions key patterns are converted to regexp using path-to-regexp; non-standard patterns may not match as expected.
fix
Ensure patterns follow path-to-regexp syntax (e.g., '/:param', '/(.*)').
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'koa2-proxy-middleware'
Package not installed or not in node_modules.
fix
Run `npm install koa2-proxy-middleware`.
TypeError: proxy is not a function
Incorrect import style (e.g., destructured import when package exports a single function).
fix
Use `const proxy = require('koa2-proxy-middleware')`.
Error: Cannot find module 'http-proxy-middleware'
Dependency not installed automatically when peer dependency.
fix
Install http-proxy-middleware explicitly: `npm install http-proxy-middleware`.
Upgrade
Version history
0.0.4latest on npm
Audit
Dependencies
http-proxy-middlewarerequiredCore proxy functionality
path-to-regexprequiredRoute pattern matching
Agent activity
2 hits · last 30 days
node
2
Resources