I follow the online examples using the latest version of nodejs and http-proxy, but I get the following error when my request is sent to the endpoint https server:
C:\Users\Me\node_modules\http-proxy\lib\http-proxy\index.js:114 throw err; Error: DEPTH_ZERO_SELF_SIGNED_CERT at SecurePair.<anonymous> (tls.js:1370:32) at SecurePair.EventEmitter.emit (events.js:92:17) at SecurePair.maybeInitFinished (tls.js:982:10) at CleartextStream.read [as _read] (tls.js:469:13) at CleartextStream.Readable.read (_stream_readable.js:320:10) at EncryptedStream.write [as _write] (tls.js:366:25) at doWrite (_stream_writable.js:226:10) at writeOrBuffer (_stream_writable.js:216:5) at EncryptedStream.Writable.write (_stream_writable.js:183:11) at write (_stream_readable.js:582:24)
My code is very simple:
var httpProxy = require('http-proxy'); var http = require('http'); var fs = require('fs'); var apimcert = fs.readFileSync('./mycert.pfx'); var proxy = httpProxy.createProxyServer({}); var options = { pfx: apimcert, passphrase : 'pAssw0rd', rejectUnauthorized : 'false', agent: false }; var server = require('https').createServer(options, function(req, res) { console.log("Got a request " + req); proxy.web(req, res, { ssl: { pfx : apimcert, passphrase : 'pAssw0rd', rejectUnauthorized : 'false'
If I set secure : false , then the request is sent to the endpoint, but explicitly sent back with the forbidden answer 403. The certificate and passphrase that I use are my endpoint servers, and I tested their operation when sending the request directly. All I want my proxy server to do is check the contents of the requests, write a message for each of them, and then redirect to the endpoint server.
I ran into this problem and tried messing with agents and strictSSL, but to no avail.
Iains source share