node-http-proxy icon indicating copy to clipboard operation
node-http-proxy copied to clipboard

https support: ERR_PROXY_CERTIFICATE_INVALID

Open GregorBiswanger opened this issue 3 years ago • 2 comments
trafficstars

Hello community, unfortunately the https proxy doesn't work for me.

The browser reports the following: ERR_PROXY_CERTIFICATE_INVALID

It works great without https. Can it be due to TLS? Isn't that supported?

GregorBiswanger avatar Aug 11 '22 20:08 GregorBiswanger

My code is:

const http = require('http'),
    fs = require('fs'),
    httpProxy = require('http-proxy');

const proxy = httpProxy.createProxyServer({
    target: 'http://localhost:3000',
    ssl: {
        key: fs.readFileSync('rootCA.key', 'utf8'),
        cert: fs.readFileSync('rootCA.pem', 'utf8')
    }
});
proxy.listen(8000);

http.createServer((request, response) => {
    const url = `https://${request.headers.host}`;
    console.log(url);

    if (url + request.url !== 'https://www.google.com/') {
        console.log('request blocked');

        response.writeHead(200, { 'Content-Type': 'text/plain' });
        response.write('request successfully proxied!' + '\n' + JSON.stringify(request.headers, true, 2));
        response.end();
    } else {
        console.log('request allowed');

        proxy.web(request, response, { target: url, changeOrigin: true });
        proxy.on('error', (e) => console.error(e));
    }

}).listen(3000);

I made the certificates with openssl.

GregorBiswanger avatar Aug 11 '22 20:08 GregorBiswanger

did you made any progress in these things because even i am working on that need little help

knuckle00 avatar Jan 13 '23 12:01 knuckle00