Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

httpxy

unjs1.6mMIT0.1.6TypeScript support: included

A full-featured HTTP proxy for Node.js.

readme

🔀 httpxy

npm version npm downloads bundle Codecov

A Full-Featured HTTP and WebSocket Proxy for Node.js forked from http-party/node-http-proxy with modern Typescript rewrite.

Usage

Install package:

# npm
npm install httpxy

# yarn
yarn add httpxy

# pnpm
pnpm install httpxy

Create proxy:

import { createServer } from "node:http";

import { createProxyServer } from "httpxy";

const proxy = createProxyServer({});

const server = createServer(async (req, res) => {
  try {
    await proxy.web(req, res, {
      target: address /* address of your proxy server here */,
    });
  } catch (error) {
    console.error(error);
    res.statusCode = 500;
    res.end("Proxy error: " + error.toString());
  }
});

server.listen(3000, () => {
  console.log("Proxy is listening on http://localhost:3000");
});

Checkout http-party/node-http-proxy for more options and examples (note: followRedirects is not supported).

Development

  • Clone this repository
  • Install latest LTS version of Node.js
  • Enable Corepack using corepack enable
  • Install dependencies using pnpm install
  • Run interactive tests using pnpm dev

License

Made with 💛

Published under MIT License.

changelog

Changelog

v0.1.6

compare changes

🩹 Fixes

  • Omit outgoing port when not required (#65)

📖 Documentation

  • Remove unsupported followRedirects option (#66)
  • Improve example (#16)

🏡 Chore

❤️ Contributors

v0.1.5

compare changes

🩹 Fixes

  • Handle client close event (#8)

🏡 Chore

❤️ Contributors

v0.1.4

compare changes

🩹 Fixes

  • Presrve search params from parsed url (8bbaacc)
  • Add target pathname currectly (#6)

💅 Refactors

  • Fix typo in defineProxyMiddleware (#4)

🏡 Chore

❤️ Contributors

  • Pooya Parsa (@pi0)
  • Jonasolesen
  • Gacek1123

v0.1.3

compare changes

🩹 Fixes

  • Presrve search params from parsed url (8bbaacc)

💅 Refactors

  • Fix typo in defineProxyMiddleware (#4)

🏡 Chore

❤️ Contributors

  • Pooya Parsa (@pi0)
  • Gacek1123

v0.1.2

compare changes

🩹 Fixes

  • Presrve search params from parsed url (8bbaacc)

❤️ Contributors

  • Pooya Parsa (@pi0)

v0.1.1

🚀 Enhancements

🩹 Fixes

  • createProxyServer options is optional (75d8e93)

💅 Refactors

📖 Documentation

🏡 Chore

❤️ Contributors