proxy-simple
v1.0.1
Published
Simple HTTP/HTTPS proxy library
Downloads
7
Maintainers
Readme
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