Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

82
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!