Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Proxy backend

Greenkeeper badge

NPM Version Build Status Test Coverage

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

Features

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

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

About

Have a backend in your code, easily proxy traffic through it according to it's status.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages