0

I need help creating a proxy server using node js to use with firefox.

the end goal is to create a proxy server that will tunnel the traffic through another proxy server (HTTP/SOCKS) and return the response back to firefox. like this

enter image description here

I wanna keep the original response received from the proxy server and also wanna support https websites as well.

Here is the code I came up with.

var http = require('http');
var request = require("request");
http.createServer(function(req, res){
    const resu = request(req.url, {
        // I wanna Fetch the proxy From database and use it here
        proxy: "<Proxy URL>"
    })
    req.pipe(resu);
    resu.pipe(res);
}).listen(8080);

But it has 2 problems.

  1. It does not support https requests.
  2. It also does not supports SOCKS 4/5 proxies.

EDIT: I tried to create a proxy server using this module. https://github.com/http-party/node-http-proxy but the problem is we cannot specify any external proxy server to send connections through.

Bubun
  • 310
  • 2
  • 14

2 Answers2

1

You have to use some middleware like http-proxy module.

Documentation here: https://www.npmjs.com/package/http-proxy

Install it using npm install node-http-proxy

This might help too: How to create a simple http proxy in node.js?

jsgrewal12
  • 138
  • 9
1

I have found a really super simple solution to the problem. We can just forward all packets as it is to the proxy server. and still can handle the server logic with ease.

var net = require('net');
const server = net.createServer()

server.on('connection', function(socket){
    var laddr = socket.remoteAddress;
    console.log(laddr)
    var to = net.createConnection({
        host: "<Proxy IP>",
        port: <Proxy Port>
    });
    socket.pipe(to);
    to.pipe(socket);
});

server.listen(3000, "0.0.0.0");
Bubun
  • 310
  • 2
  • 14