Skip to content

Instantly share code, notes, and snippets.

@InputNeuron
Created April 11, 2019 17:55
Show Gist options
  • Select an option

  • Save InputNeuron/84be6324af8a926d73b0940fa67ae03a to your computer and use it in GitHub Desktop.

Select an option

Save InputNeuron/84be6324af8a926d73b0940fa67ae03a to your computer and use it in GitHub Desktop.
function handleResponse(res: functions.Response, next?: NextFunction) {
const url = 'https://firebasestorage.googleapis.com/v0/b/polar-32b0f.appspot.com/o/stash%2F12RMNjmX1PLwqN5fRXzh89Yi7tbL24e5VfCNs4Nq.pdf?alt=media&token=0a2708be-ef63-4791-a338-a3c887b73b19';
const started = Date.now();
let idx: number = 0;
https.get(url, (dataResponse) => {
res.writeHead(dataResponse.statusCode!,
dataResponse.statusMessage,
dataResponse.headers);
res.flushHeaders();
dataResponse.on("data", data => {
res.write(data);
});
dataResponse.on("end", () => {
res.end();
if (next) {
next();
}
});
dataResponse.on("error", (err) => {
res.end();
if (next) {
next();
}
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment