Skip to content

Commit

Permalink
Merge pull request #86 from UKHomeOffice/bugfix/stream-response
Browse files Browse the repository at this point in the history
Pipe response immediately
  • Loading branch information
wheelsandcogs authored Apr 23, 2019
2 parents b2dc6bd + d7ed848 commit 559e93b
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pages/reporting/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ module.exports = settings => {
app.get('/:year', (req, res, next) => {
const archive = archiver('zip');

res.attachment(`nts-${req.params.year}.zip`);
archive.pipe(res);

req.api('/search/projects?limit=1')
.then(response => {
return req.api(`/search/projects?limit=${response.json.meta.count}`);
Expand Down Expand Up @@ -42,9 +45,7 @@ module.exports = settings => {

})
.then(() => {
res.attachment(`nts-${req.params.year}.zip`);
archive.finalize();
archive.pipe(res);
})
.catch(err => next(err));
});
Expand Down

0 comments on commit 559e93b

Please sign in to comment.