I'd like to provide a proxy in node.js. Only one request should consume the original data-source and send data to list of connected clients. What is better approach?
1/ keep clients in a list and send every data-chunk to each of them, eg.:
// on client connection ('res' is client's response stream):
self.clients.push(res);
// ... then, on data event:
for (var i = self.clients.length; i--;) {
self.clients[i].write(someDataChunk);
}
2/ or, create one duplex (let's say PassThrough) stream, write data-chunks into it, and simply pipe output to every client's request?
var out = new PassThrough();
out.write(someDataChunk);
out.pipe(res); // again, 'res' is client's response stream
3/ or any other, better approach?