You're viewing a comment by Jack and its responses.

Jack Permalink
November 04, 2017, 03:24

as of 20171104, your code is not working anymore with recent nodejs and its http module.

Comment Responses

Javier Permalink
November 08, 2018, 00:15

This is an updated version that works with Node 10. I've made some cosmetic changes but the important part is that http no longer has a createClient function, instead you just do http.request(...

let http = require('http');

http.createServer((request, response) => {
  console.log('Received request for ', request.url);
  let proxyRequest = http.request(request.url, {
    headers: request.headers,
    method: request.method
  proxyRequest.addListener('response', proxyResponse => {
    console.log('Received response from ', request.url);
    proxyResponse.addListener('data', chunk => response.write(chunk, 'binary'));
    proxyResponse.addListener('end', () => response.end());
    response.writeHead(proxyResponse.statusCode, proxyResponse.headers);
  request.addListener('data', chunk => proxyRequest.write(chunk, 'binary'));
  request.addListener('end', () => proxyRequest.end());

Reply To This Comment

(why do I need your e-mail?)

(Your twitter handle, if you have one.)

Type the word "cloud_215": (just to make sure you're a human)

Please preview the comment before submitting to make sure it's OK.