node-http-proxy
node-http-proxy copied to clipboard
https support: ERR_PROXY_CERTIFICATE_INVALID
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?
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.
did you made any progress in these things because even i am working on that need little help