# http-proxy-lo

> [![NPM version][npm-image]][npm-url] [![build status][travis-image]][travis-url] [![Test coverage][codecov-image]][codecov-url] [![David deps][david-image]][david-url] [![Known Vulnerabilities][snyk-image]][snyk-url] [![npm download][download-image]]

Latest version **1.0.0** (published 2022-07-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install http-proxy-lo
pnpm add http-proxy-lo
yarn add http-proxy-lo
bun add http-proxy-lo
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2022-07-04 |
| First published | 2022-07-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=10.0.0 |
| Dependencies | 3 |
| Unpacked size | 15.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | lo |
| Maintainers | lo_20211014 |

## Links

- npm: https://www.npmjs.com/package/http-proxy-lo
- Repository: https://github.com/llh1187/egg-http-proxy
- Homepage: https://github.com/llh1187/egg-http-proxy#readme
- Issues: https://github.com/llh1187/egg-http-proxy/issues
- npm.io page: https://npm.io/package/http-proxy-lo

## Dependencies (3)

- [address](https://npm.io/package/address.md) ^1.1.2
- [formstream](https://npm.io/package/formstream.md) ^1.1.0
- [content-type](https://npm.io/package/content-type.md) ^1.0.4

## Recent versions

- 1.0.0 (latest) — 2022-07-04

## README

# @eggjs/http-proxy

[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[![Test coverage][codecov-image]][codecov-url]
[![David deps][david-image]][david-url]
[![Known Vulnerabilities][snyk-image]][snyk-url]
[![npm download][download-image]][download-url]

[npm-image]: https://img.shields.io/npm/v/@eggjs/http-proxy.svg?style=flat-square
[npm-url]: https://npmjs.org/package/@eggjs/http-proxy
[travis-image]: https://img.shields.io/travis/eggjs/egg-http-proxy.svg?style=flat-square
[travis-url]: https://travis-ci.org/eggjs/egg-http-proxy
[codecov-image]: https://img.shields.io/codecov/c/github/eggjs/egg-http-proxy.svg?style=flat-square
[codecov-url]: https://codecov.io/github/eggjs/egg-http-proxy?branch=master
[david-image]: https://img.shields.io/david/eggjs/egg-http-proxy.svg?style=flat-square
[david-url]: https://david-dm.org/eggjs/egg-http-proxy
[snyk-image]: https://snyk.io/test/npm/@eggjs/http-proxy/badge.svg?style=flat-square
[snyk-url]: https://snyk.io/test/npm/@eggjs/http-proxy
[download-image]: https://img.shields.io/npm/dm/@eggjs/http-proxy.svg?style=flat-square
[download-url]: https://npmjs.org/package/@eggjs/http-proxy

A simple http proxy base on egg httpclient.

## Install


```bash
$ npm i @eggjs/http-proxy --save
```

```js
// {app_root}/config/plugin.js
exports.httpProxy = {
  enable: true,
  package: '@eggjs/http-proxy',
};
```

## Usage

```js
/**
 * @param {String} host - target host.
 * @param {Object} [options] - options for request, see https://github.com/node-modules/urllib
 * @param {Boolean} [options.withCredentials] - if true, will send cookie when cors
 * @param {Function} [options.rewrite] - rewrite target url obj
 */
await ctx.proxyRequest(host, options);
```

### target host

```js
// current url: http://eggjs.org/api/user -> http://github.com/api/user
await ctx.proxyRequest('github.com');
```

### rewrite path

```js
// current url: http://eggjs.org/api/user -> http://github.com/egg/eggjs/api/user
await ctx.proxyRequest('github.com', {
  rewrite(urlObj) {
    urlObj.pathname = '/egg/eggjs/api/user';
    return urlObj;
  },
});
```

### modify response

```js
await ctx.proxyRequest('github.com', {

  streaming: false,

  async beforeResponse(proxyResult) {
    proxyResult.headers.addition = 'true';
    // streaming=false should modify `data`, otherwise use stream to handler proxyResult.res yourself
    proxyResult.data = proxyResult.data.replace('github.com', 'www.github.com');
    return proxyResult;
  },
});
```

## Configuration

```js
// {app_root}/config/config.default.js
exports.httpProxy = {

};
```

see [config/config.default.js](config/config.default.js) for more detail.

## Questions & Suggestions

Please open an issue [here](https://github.com/eggjs/egg/issues).

## License

[MIT](LICENSE)

---
_Source: https://npm.io/package/http-proxy-lo · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
