Node.js - listener must be a function error

后端 未结 2 1904
既然无缘
既然无缘 2021-01-13 13:14

I\'m trying to convert the accepted answer on (How to create a simple http proxy in node.js?) from http to https.

When I try to access the proxy from my browser, the

相关标签:
2条回答
  • 2021-01-13 13:30

    I solved this error by passing the function name as the param rather than the variable that holds the function

    0 讨论(0)
  • 2021-01-13 13:36

    Looks like you've got the arguments to https.request wrong (http://nodejs.org/api/https.html#https_https_request_options_callback). Should just be:

    var proxy = https.request(options, function(res) {
       res.pipe(client_res, {
         end: true
       });
     });
    

    Your certificate information should be included in the options object, from the linked page:

    var options = {
      hostname: 'encrypted.google.com',
      port: 443,
      path: '/',
      method: 'GET',
      key: fs.readFileSync('test/fixtures/keys/agent2-key.pem'),
      cert: fs.readFileSync('test/fixtures/keys/agent2-cert.pem')
    };
    options.agent = new https.Agent(options);
    
    var req = https.request(options, function(res) {
      ...
    }
    
    0 讨论(0)
提交回复
热议问题