create proxy server code example

Example 1: proxy server

A proxy server is kind of gateway between
our application and the internet. 
Proxy servers provide varying
levels of functionality, security, and 
privacy depending on your use case, needs,
or company policy.

Example 2: how to make a proxy server node.js

var fs = require('fs');

var http = require('http'),

var https = require('https'),

var httpProxy = require('http-proxy');

isHttps = true;

var options = {

  ssl: {

    key: fs.readFileSync('valid-key.pem'),

    cert: fs.readFileSync('valid-cert.pem')

  }

};

proxyServer = proxy.createProxyServer({target:'http://127.0.0.1:9000'});

proxyServer.listen(8000);

if (isHttps){

   server = https.createServer(options.ssl, function(req, res) {

     console.log(“https request”);

     proxyServer.web(req, res, { target: req.url });

     proxyServer.on('error', function(e) {

  console.log("Error in proxy call");

     });

     proxyServer.listen(443);

   });

}else{

  server = http.createServer(function (req, res) {

  console.log(req.url);

  proxyServer.web(req, res, { target: req.url });

  proxyServer.on('error', function(e) {

   console.log("Error in proxy call");

  });

    });

 }

 server.listen(9000);

Example 3: proxy server windows

netsh interface portproxy add v4tov4 listenport=80 connectaddress=ip-of-server-on-internet connectport=23 listenaddress=ip-of-windows-machine protocol=tcp