Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

86
Visualizações
Node.js Proxy Server on Localhost Always Returns Empty Response

I've been working on a personal project lately, and it involves intercepting any HTTP/S requests coming from my PC to external servers (that includes requesting through browsers, curl, etc.) and sometimes redirecting requests to a personal page depending on the requested hostname.

In order to get a proof-of-concept for intercepting and forwarding requests, I built a quick HTTPS proxy server in Node.js. It shouldn't really do anything other than printing some information about each request and forwarding it to where it was supposed to go.

Here's the main part of it:

var https = require('https');
var httpProxy = require('http-proxy');
var fs = require('fs');
var path = require('path');

const options = {
    ssl: {
      key: fs.readFileSync(path.resolve(__dirname, './mycert.key'), 'utf8'),
      cert: fs.readFileSync(path.resolve(__dirname, './mycert.crt'), 'utf8')
    },
    secure: false,
    toProxy: true
  }
const proxy = httpProxy.createProxyServer(options);

const httpsServer = https.createServer(options.ssl, (req, res) => {
    console.log("WEBSERVER")
    console.log(req.headers.host);
    proxy.web(req, res, {
      target: req.headers.host,
    })
})

const httpsListener = httpsServer.listen(8080);

console.log("LISTENING ON 8080")

Problem is, whenever I turn my Windows proxy settings to go to my new server, any request made through a browser just gives me an ERR_EMPTY_RESPONSE, and nothing gets printed out in the console where I run the proxy.

If I do an HTTPS request directly to the proxy it does print what I need out, but obviously doesn't take me anywhere.

Any ideas about what I should try? To be honest, I'm not sure if it is even possible to make a "localhost" proxy server, so I might be completely off track :/.

Thanks!

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda