Server middleware - get file from remote and forward to client

I’m adding a Blog to my site/app using the Blogger api. In Cordova I want to redirect the images via my own server (via my own CDN) so I don’t have to update the app config file with more access rules and wait for all my users to upgrade the app.

It mostly works, my server code receives the request, fetches the image and forwards it to the client, but the image doesn’t display.

I’m obviously doing something wrong here:

WebApp.connectHandlers.use('/blogimg', (req, res/*, next*/) => {
	console.log('/blogimg', req.query.p);

	var content = "";
	req.on('data', Meteor.bindEnvironment(data => content += data));

	req.on('end', Meteor.bindEnvironment(() => {
		HTTP.call('GET', req.query.p, (err, file) => {
            console.log(file.headers);
            res.setHeader('Access-Control-Allow-Origin', '*');
            res.setHeader("Access-Control-Allow-Methods", "GET,HEAD,OPTIONS,POST,PUT");
            res.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization");
            res.setHeader('cache-control', file.headers['cache-control']);
            res.setHeader('content-type', file.headers['content-type']);
            res.writeHead(file.statusCode);
            res.end(file.content);
		} );
    }));
});

The res.end() can take a 2nd encoding parameter. Do I need to set that to something?

Is there a neater way to completely forward this request to the remote server?

file.headers looks like this:

{
   'access-control-expose-headers': 'Content-Length',
   etag: '"vb4"',
   expires: 'Mon, 04 May 2020 18:21:10 GMT',
   'content-disposition': 'inline;filename="group_presentation.png"',
   'content-type': 'image/png',
   vary: 'Origin',
   'access-control-allow-origin': '*',
   'timing-allow-origin': '*',
   'x-content-type-options': 'nosniff',
   date: 'Mon, 04 May 2020 05:32:46 GMT',
   server: 'fife',
   'content-length': '49365',
   'x-xss-protection': '0',
   age: '1465',
   'cache-control': 'public, max-age=86400, no-transform',
   'alt-svc': 'h3-Q050=":443"; ma=2592000,h3-Q049=":443"; ma=2592000,h3-Q048=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"',
   connection: 'close'
}

I finally found this Stackoverflow answer and came up with this:

const https = require('https');

WebApp.connectHandlers.use('/blogimg', (request, response) => {
    console.log('/blogimg ' + request.query.p);

	request.on('data', () => {});

	request.on('end', Meteor.bindEnvironment(() => {
		response.setHeader('Access-Control-Allow-Origin', '*');
		response.setHeader("Access-Control-Allow-Methods", "GET,HEAD,OPTIONS,POST,PUT");
		response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization");
        response.setHeader('cache-control', 'public, max-age=31536000');
        const connector = https.request(request.query.p, res => res.pipe(response) );
        request.pipe(connector);
    }));
});