Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions docs/modules/http-proxy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
description: Modern alternatives to the http-proxy package for HTTP and WebSocket proxying in Node.js
---

# Replacements for `http-proxy`

[`http-proxy`](https://github.com/http-party/node-http-proxy) has not been maintained since 2020 and has known crashes, memory leaks, and socket issues on modern Node.js versions.

## `httpxy`

[`httpxy`](https://github.com/unjs/httpxy) is a maintained fork of `http-proxy` with critical upstream bug fixes, zero dependencies, and additional helpers such as `proxyFetch` and `proxyUpgrade`.

Example:

```ts
import httpProxy from 'http-proxy' // [!code --]
import { createProxyServer } from 'httpxy' // [!code ++]
import { createServer } from 'node:http'

const proxy = httpProxy.createProxyServer({}) // [!code --]
const proxy = createProxyServer({}) // [!code ++]

const server = createServer((req, res) => {
proxy.web(req, res, { target: 'http://localhost:8080' }) // [!code --]
proxy.web(req, res, { target: 'http://localhost:8080' }) // [!code ++]
})

server.on('upgrade', (req, socket, head) => {
proxy.ws(req, socket, head, { target: 'http://localhost:8080' }) // [!code --]
proxy.ws(req, socket, { target: 'http://localhost:8080' }, head) // [!code ++]
})
```

## `http-proxy-3`

[`http-proxy-3`](https://github.com/sagemathinc/http-proxy-3) is a TypeScript rewrite with API compatibility, HTTP/2 support, and production use in Vite, JupyterHub, and CoCalc.

Example:

```ts
import httpProxy from 'http-proxy' // [!code --]
import { createProxyServer } from 'http-proxy-3' // [!code ++]
import { createServer } from 'node:http'

const proxy = httpProxy.createProxyServer({}) // [!code --]
const proxy = createProxyServer({}) // [!code ++]

const server = createServer((req, res) => {
proxy.web(req, res, { target: 'http://localhost:8080' })
})

server.on('upgrade', (req, socket, head) => {
proxy.ws(req, socket, head, { target: 'http://localhost:8080' }) // [!code --]
proxy.ws(req, socket, { target: 'http://localhost:8080' }, head) // [!code ++]
})
```
16 changes: 16 additions & 0 deletions manifests/preferred.json
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,12 @@
"replacements": ["html-minifier-next"],
"url": {"type": "e18e", "id": "html-minifier"}
},
"http-proxy": {
"type": "module",
"moduleName": "http-proxy",
"replacements": ["httpxy", "http-proxy-3"],
"url": {"type": "e18e", "id": "http-proxy"}
},
"inherits": {
"type": "module",
"moduleName": "inherits",
Expand Down Expand Up @@ -3175,6 +3181,16 @@
"type": "documented",
"replacementModule": "html-minifier-next"
},
"http-proxy-3": {
"id": "http-proxy-3",
"type": "documented",
"replacementModule": "http-proxy-3"
},
"httpxy": {
"id": "httpxy",
"type": "documented",
"replacementModule": "httpxy"
},
"import.meta.resolve": {
"id": "import.meta.resolve",
"type": "native",
Expand Down