Proxy problem created with nodejs

0

I am creating a web proxy with nodejs and I have a problem. This is the index of the view:

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">

    <title>Hola</title>
  </head>
  <body>
    <div class="container mt-5">
      <div class="row mt-5">
        <div class="mx-auto mt-5">
          <div class="form-group">
            <form class="" method="get" action="./">
              <input type="text" class="form-control" id="url" placeholder="www.example.com" name="url">
            </form>
          </div>
        </div>
      </div>
    </div>
  </body>
</html>

and this is the server file:

const http = require("http");
const url = require("url");
const request = require("request");
const fs = require('fs')
var server = http.createServer(onRequest);

function onRequest(req, res) {
  var queryData = url.parse(req.url, true).query;
  if (queryData.url) {
    request({ url: "http://"+ queryData.url })
      .on("error", function(e) {
        res.end(e);
      })
      .pipe(res);
  } else {
    fs.readFile("index.html", (err, html) => {
      if (err) {
        console.log(err)
      }
      else {
        res.write(html);
        res.end();
      }
    });
  }
}

server.listen(80);

Everything works almost perfectly, because I send the data by form and all good. He loads the page perfectly, for example www.google.com, it lets me navigate between pages and everything, but once inside it I try to do a Google search for example, it returns me to the index of the view and does not make me Search, then redirect me to a link like this: link and in the server that I have in linux the same thing happens to me, only instead of localhost I see the name of the domain that I have anchored there to the server . When I try to access Twitter or any page that contains a login to access my account, it takes me out of the proxy and sends me to the normal page. Does anyone have any idea what I'm doing wrong?

    
asked by Diesan Romero 25.08.2018 в 22:37
source

0 answers