0

I'm using http-proxy module and I'm trying to send the request to port 1234 and gets its reply back. But in the apache logs I can see that request is only to /. The documentation says to use toProxy: true in order to pass the URL but it isn't working.

https://github.com/http-party/node-http-proxy

  • toProxy: true/false, passes the absolute URL as the path (useful for proxying to proxies)

Here is the code:

var http = require('http');
var httpProxy = require('http-proxy');
var proxy = httpProxy.createProxyServer();
var fs = require('fs');

http.createServer(function(req, res) {
    return proxy.web(req, res, { target: {host: 'localhost', port: 1234},
        ssl: {
                key: fs.readFileSync('/root/test.pem', 'utf8'),
                cert: fs.readFileSync('/root/test_cert.pem', 'utf8')
                        },
                toProxy: true
        });

}).listen(3000);

I'm using curl to test and checking the apache logs which is listening on port 1234.

curl -v http://localhost:3000/getsomething.html
1
  • Show us your apache config Commented Apr 20, 2020 at 10:48

1 Answer 1

0

Figured it out. I had to include protocol.

return proxy.web(req, res, { target: { protocol: 'https:', host: 'localhost', port: 1234},
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.