Registry / devops / koa-http-proxy-middleware

koa-http-proxy-middleware

JSON →
library0.0.2jsnpmunverified

Koa@2.x middleware for HTTP proxying, powered by http-proxy. Version 0.0.2. Provides a simple way to proxy requests to another target with options like path rewriting, event handling, and logging. Differentiators: native Koa support (async/await), Promise-based flow, and integration with match-path-plus for URL matching. Released on npm, no recent updates.

npm install koa-http-proxy-middleware
INSTALL
IMPORT
SIG · KOA-HTTP-PROXY-MID
K
koa-http-proxy-middleware
devopsjavascriptv0.0.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

httpProxy
import { httpProxy } from 'koa-http-proxy-middleware'
const httpProxy = require('koa-http-proxy-middleware')
Named export only; default export does not exist.
httpProxy (CommonJS)
const { httpProxy } = require('koa-http-proxy-middleware')
CommonJS destructuring required.
middleware usage
app.use(httpProxy('/pattern', { target: 'http://example.com' }))
app.use(httpProxy({ target: 'http://example.com' }))
First argument must be a URL pattern string.

Sets up a Koa server with proxy middleware redirecting /api to external API.

import Koa from 'koa'; import { httpProxy } from 'koa-http-proxy-middleware'; const app = new Koa(); app.use(httpProxy('/api', { target: 'https://jsonplaceholder.typicode.com', changeOrigin: true, rewrite: path => path.replace(/^\/api/, ''), logs: true })); app.listen(3000, () => console.log('Proxy server running on port 3000'));
Debug
Known issues
gotchaThe httpProxy export is a function that returns middleware; it must be called with a URL pattern and options.
fix
Ensure you call httpProxy(pattern, options) in your app.use().
affects: >=0.0.1
gotchaEvents like 'error', 'proxyReq', 'proxyRes' are registered globally on the proxy instance. Only the first set of events is registered; subsequent calls override.
fix
Define events once; avoid using events in multiple middleware instances.
affects: >=0.0.1
deprecatedThe 'logs' option uses console.log; no built-in logging framework.
fix
Implement custom logging via events if needed.
affects: >=0.0.1
Errors
Common errors & fixes
TypeError: httpProxy is not a function
Importing default instead of named export.
fix
Use named import: import { httpProxy } from 'koa-http-proxy-middleware'
Error: Pattern must be a string or RegExp
Calling httpProxy without a first argument or with wrong type.
fix
Provide a URL pattern string or RegExp as first argument.
Upgrade
Version history
0.0.2latest on npm
Audit
Dependencies
http-proxyrequiredCore proxying functionality
match-path-plusrequiredURL pattern matching
Agent activity
5 hits · last 30 days
node
2
Resources
koa-http-proxy-middleware — npm install koa-http-proxy-middleware · libregistry