# simple-http-proxy

> Simple proxy middleware

Latest version **0.5.11** (published 2014-05-09) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.5.11 |
| Published | 2014-05-09 |
| First published | 2013-01-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 9 |
| Author | Cameron Bytheway |
| Maintainers | camshaft |
| Keywords | proxy, simple |

## Links

- npm: https://www.npmjs.com/package/simple-http-proxy
- Repository: https://github.com/simple-app/simple-http-proxy
- Issues: https://github.com/simple-app/simple-http-proxy/issues
- npm.io page: https://npm.io/package/simple-http-proxy

## Dependencies (1)

- [debug](https://npm.io/package/debug.md) ~0.7.2

## Recent versions

- 0.5.11 (latest) — 2014-05-09
- 0.5.10 — 2014-01-28
- 0.5.9 — 2014-01-24
- 0.5.8 — 2013-12-18
- 0.5.7 — 2013-11-08
- 0.5.6 — 2013-08-31
- 0.5.5 — 2013-07-15
- 0.5.4 — 2013-07-10
- 0.5.3 — 2013-05-28
- 0.5.2 — 2013-04-01
- 0.5.1 — 2013-03-24
- 0.5.0 — 2013-02-22
- 0.4.0 — 2013-01-31
- 0.3.1 — 2013-01-31
- 0.3.0 — 2013-01-30
- … 2 more at https://npm.io/package/simple-http-proxy/versions

## README

simple-http-proxy [![Build Status](https://travis-ci.org/flokk/simple-http-proxy.png?branch=master)](https://travis-ci.org/flokk/simple-http-proxy)
=================

Simple proxy middleware for connect/express

Usage
-----

Create an http app
```js
/**
 * Module dependencies
 */
var express = require('express');
var proxy = require('simple-http-proxy');

/**
 * Expose the app
 */
var app = module.exports = express();

/**
 * Mount the proxy middleware
 */
app.use('/api', proxy('http://my.other.host.com/path-to-proxy'));
```

Make the request
```sh
$ curl http://localhost:5000/api

<h1>Welcome to my.other.host.com/path-to-proxy</h1>
```

You can also specify some options as a second parameter

```
app.use('/api', proxy('http://my.other.host.com/path-to-proxy', opts));
```

### Options

#### `cookies`

Disable sending cookies by passing `false`; on by deafult.

#### `xforward`

Setting this to `true` will set `x-forwarded-proto`, `x-forwarded-host`, `x-forwarded-port` and `x-forwarded-path` headers.

Passing an object will override the header names:

```js
{
  proto: 'x-orig-proto',
  host: 'x-orig-host',
  port: 'x-orig-port',
  path: 'x-orig-path'
}
```

#### `timeout`

A positive millisecond value for the timeout of the request. Defaults to 10000 (10s).

Setting it to `false` will disable the timeout.

#### `onrequest`

A function to be called on each request. The first parameter will be the [options object](http://nodejs.org/api/http.html#http_http_request_options_callback) for the http request. The second will be the [request object](http://nodejs.org/api/http.html#http_class_http_clientrequest).

This can be used to change any of the http options for a given request.

#### `onresponse`

A function to be called on each response. The first parameter will be the [incoming message](http://nodejs.org/api/http.html#http_http_incomingmessage) for a given request. The second will be the [server response object](http://nodejs.org/api/http.html#http_class_http_serverresponse).

If this function returns `true` the default pipe will not be used and will be up to the `onresponse` function to implement that behavior. This is useful for rewriting responses that are sent to the client.

Tests
-----

```sh
$ npm test
```

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