proxy-simple

1.0.1 • Public • Published

npm NPM version dependencies Status devDependencies Status

proxy-simple

Simple HTTP/HTTPS proxy server library written on TypeScript.

Installation

$ npm install proxy-simple --save-dev

Usage

const proxySimple = require('proxy-simple');
 
const proxy = proxySimple({
    host: 'localhost',
    port: 1234
});
 
proxy.start();

Advanced usage

const proxySimple = require('proxy-simple');
 
const proxy = proxySimple({
    host: 'localhost',
    port: 1234,
    debug: true
});
 
proxy.handler((options) => {
    if (options.client.host !== 'localhost') {
        return 403;
    }
    
    if (options.target.port !== 80 || options.target.port !== 443) {
        return 403;
    }
    
    if (options.account) {
        if (options.account.user === 'user' && options.account.password === 'password') {
            return 200;
        }
    }
 
    return {
        code: 407,
        body: 'auth required!'
    };
});
 
proxy.success((options) => {
    console.log(
        'client:', options.client.host,
        'target:', options.target.host,
        'downloaded:', options.downloaded,
        'uploaded:', options.uploaded
    );
});
 
proxy.start();
 
process.on('SIGINT', () => {
    proxy.shutdown();
    process.exit(1);
});
 

Development

Build
$ npm run build
Watch
$ npm run watch

Package Sidebar

Install

npm i proxy-simple

Weekly Downloads

18

Version

1.0.1

License

MIT

Last publish

Collaborators

  • zyxd