Skip to content

A node simple based on net module http and https forwarding proxy

Notifications You must be signed in to change notification settings

Glitnirian/node-net-proxy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

node-net-proxy

A simple net http https forwarding proxy! Like smartProxy and vpn's! You can use it with your browser or your system to go out!

So if set in an external server! You can change your IP using it!

You can learn and understand some of the basics of a forwarding proxy! As this use the net module! And so all play at the TCP level!

You can build upon it too! And take it as a base!

Research things like http tunneling! And CONNECT http Method! And BOSH!

And this module is a great piece to create proxies for testing! That was our usage at our company!

And we use it as simple forwarding proxy too!

This proxy use the http CONNECT method for https (end to end tunnel and encryption). And simple forwarding for http.

Typescript

Build using typescript! And fully support typing!

Install

npm install net-proxy --save

How to use

We use the class ProxyServer

Class Signature:

class ProxyServer {
    public port: number;
    public server: net.Server;
    
    constructor(options: IOptions);
    public awaitStartedListening();
}

interface IOptions {
    port: number
}

import

import { ProxyServer } from 'net-proxy';

Init

// init
const proxy = new ProxyServer({
    port: proxyPort
});

// waiting for the server to start
proxy.awaitStartedListening()
    .then(() => {
        handleDone();
    })
    .catch(() => {
        handleDone();
    });

Another example

const proxy = new ProxyServer({
    port: proxyPort
});

proxy.server.on('data', (data: any) => { // accessing the server instance
    console.log(data);
});

await proxy.awaitStartedListening(); // await server to start

// After server started

let proxyUrl = `http://localhost:${proxyPort}`;

let agent = getProxyHttpAgent({
    proxy: proxyUrl,
    endServerProtocol: 'http:'
});

const response = await fetch(`http://localhost:${localApiServerPort}`, {
    method: 'GET',
    agent
}); // this call will pass through the proxy

About

A node simple based on net module http and https forwarding proxy

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published