# proxy-backend

> Proxy-backend is an HTTP programmable proxying library that supports websockets. It is suitable for implementing components such as reverse proxies and load balancers

Latest version **1.0.2** (published 2018-12-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install proxy-backend
pnpm add proxy-backend
yarn add proxy-backend
bun add proxy-backend
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2018-12-08 |
| First published | 2018-05-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 22.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Eyald |
| Maintainers | hiscojs |
| Keywords | http proxy, proxy, backend, healthcheck, monitor, status |

## Links

- npm: https://www.npmjs.com/package/proxy-backend
- Repository: https://github.com/hisco/proxy-backend
- Homepage: https://github.com/hisco
- Issues: https://github.com/hisco/proxy-backend/issues
- npm.io page: https://npm.io/package/proxy-backend

## Dependencies (2)

- [http-proxy](https://npm.io/package/http-proxy.md) ^1.16.2
- [status-monitor](https://npm.io/package/status-monitor.md) ^1.0.3

## Recent versions

- 1.0.2 (latest) — 2018-12-08
- 1.0.1 — 2018-08-10
- 1.0.0 — 2018-05-29

## README

# Proxy backend

[![Greenkeeper badge](https://badges.greenkeeper.io/hisco/proxy-backend.svg)](https://greenkeeper.io/)

[![NPM Version][npm-image]][npm-url]
[![Build Status][travis-image]][travis-url]
[![Test Coverage][coveralls-image]][coveralls-url]

`proxy-backend` wrapps `node-http-proxy` while monitoring the backend 
status with `status-monitor`.

## Features
  * Status checks / health checks , full features at [status-monitor](https://www.npmjs.com/package/status-monitor) .
  * Proxy http/websockets , full features at [node-http-proxy (http-proxy)](https://www.npmjs.com/package/http-proxy) .
  * Proxy traffic based on backend status.

`node-http-proxy` is by far the best library to proxy http traffic.
It was just missing some healthchecks(`status-monitor`) to the destination it's forwarding to.

## Simple usage
The following example is an express website that proxy to a remote server only when it's valid
```js
const {ProxyBackend} = require('proxy-backend');
const proxyBackend = new ProxyBackend({
    proxyOptions : {
        target : 'http://example.com'
    },
    monitorOptions : {
        requestOptions : {
            url : 'http://example.com'
        }
    },
    onWebUnavailable(req , res){
        res.status(503).send(`example.com is down =( `)
    }
});
proxyBackend.proxy.on('proxyRes' , (proxyRes, req, res)=>{
    delete proxyRes.headers['cache-control']
    delete proxyRes.headers['etag']
})
proxyBackend.start();
proxyBackend.statusMonitor.on('testResult',(testResult)=>{
    console.log(`Just finished a test it was ${testResult.status}`)
})
proxyBackend.statusMonitor.on('statusChange',(status)=>{
    console.log(`Ok now I'm sure that server is ${status}`)
})
 
 //express....
const express = require('express')
const app = express()

app.disable('etag')
app.get('/', (req, res) => {
    req.headers.host = 'example.com';
    proxyBackend.web(req , res);
})

app.listen(3000, () => console.log('Example app listening on port 3000!'))


```
## License

  [MIT](LICENSE)

[npm-image]: https://img.shields.io/npm/v/proxy-backend.svg
[npm-url]: https://npmjs.org/package/proxy-backend
[travis-image]: https://img.shields.io/travis/hisco/proxy-backend/master.svg?style=flat-square
[travis-url]: https://travis-ci.org/hisco/proxy-backend
[coveralls-image]: https://coveralls.io/repos/github/hisco/proxy-backend/badge.svg?branch=master
[coveralls-url]: https://coveralls.io/github/hisco/proxy-backend?branch=master

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