I am creating a webproxy with nodejs to be able to access "anonymously" to another site, so this is my server:
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: 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(htm);
res.end();
}
});
}
}
server.listen(80);
Fortunately, my eyesight loads:
<!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="post">
<input type="text" class="form-control" id="url" placeholder="www.example.com">
</form>
</div>
</div>
</div>
</div>
</body>
</html>
Even the proxy works for me, since I would only have to add the url of the page I want to visit to the variable called url in the header as follows: link and go, get it right. What I want to do is a kind of get request for the url variable to access the input value of the form, but I do not have the slightest idea. Does anyone have any ideas?