Registry / web-framework / koa-http2-proxy

koa-http2-proxy

JSON →
library0.0.4jsnpmunverified

A middleware for Koa that configures http2-proxy to reverse-proxy HTTP/HTTPS/WebSocket requests with minimal setup. Version 0.0.4 (latest) provides context matching via path strings or glob patterns, path rewriting, virtual host routing, and WebSocket support. It is a fork of http-proxy-middleware adapted for Koa's async middleware pattern and HTTP/2. Lightweight alternative to koa-proxies or koa-proxy, with similar API to http-proxy-middleware but natively async. Release cadence is low; no updates since 2022.

npm install koa-http2-proxy
INSTALL
IMPORT
SIG · KOA-HTTP2-PROXY
K
koa-http2-proxy
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('koa-http2-proxy');
import proxy from 'koa-http2-proxy';
This package does not ship ESM; use CommonJS require. There is no default ES import.
proxy function
import proxy from 'koa-http2-proxy'; // use with bundler that supports CJS interop
const { proxy } = require('koa-http2-proxy');
The module exports a single function as default; named destructuring fails.
TypeScript types
// @ts-ignore import proxy from 'koa-http2-proxy';
import proxy from 'koa-http2-proxy'; // types missing
No TypeScript declarations included; use @ts-ignore or create custom .d.ts.

Creates a Koa app that proxies all requests to httpbin.org with changeOrigin true for virtual hosting.

const Koa = require('koa'); const proxy = require('koa-http2-proxy'); const app = new Koa(); app.use(proxy({ target: 'http://httpbin.org', changeOrigin: true })); app.listen(3000, () => { console.log('Proxy server running on http://localhost:3000'); console.log('Try: curl http://localhost:3000/ip => httpbin.org/ip'); });
Debug
Known issues
gotchaThe package does not support ES modules (ESM). require() is the only import method.
fix
Use CommonJS require() or configure your bundler to handle CJS dependencies.
affects: >=0.0.1
gotchaNo TypeScript type definitions included; TypeScript users will need to define their own types or use @ts-ignore.
fix
Create a declaration file (e.g., koa-http2-proxy.d.ts) or use @ts-ignore.
affects: >=0.0.1
gotchaWebSocket proxying requires manual upgrade handling via server.on('upgrade') because Koa does not handle WebSocket upgrades automatically.
fix
Implement a custom upgrade handler using the proxy.ws method: server.on('upgrade', proxy.upgrade).
affects: >=0.0.1
Errors
Common errors & fixes
Error: Cannot find module 'koa-http2-proxy'
Package not installed or path incorrect.
fix
Run `npm install koa-http2-proxy` and ensure require path is correct.
TypeError: proxy is not a function
Using ES import syntax (import) instead of require.
fix
Change from `import proxy from 'koa-http2-proxy'` to `const proxy = require('koa-http2-proxy')`.
Error: listen EADDRINUSE :::3000
Port 3000 already in use.
fix
Use a different port or kill the process using port 3000: `kill $(lsof -t -i:3000)`.
Upgrade
Version history
0.0.4latest on npm
Audit
Dependencies
http2-proxyrequiredCore proxy functionality; wraps http2-proxy for HTTP/2 support
micromatchoptionalContext path matching with glob patterns
Agent activity
2 hits · last 30 days
node
2
Resources
koa-http2-proxy — npm install koa-http2-proxy · libregistry