Skip to content

Commit 05132ac

Browse files
committed
make chunked responses opt-in
1 parent 78d30f0 commit 05132ac

2 files changed

Lines changed: 202 additions & 159 deletions

File tree

src/index.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ function fastbootExpressMiddleware(distPath, options) {
3232
.then(success, failure);
3333

3434
function success(result) {
35+
if (opts.chunkedResponse) {
3536
result.chunks()
3637
.then(chunks => {
3738
let headers = result.headers;
@@ -59,6 +60,30 @@ function fastbootExpressMiddleware(distPath, options) {
5960
res.status(500);
6061
next(error);
6162
});
63+
} else {
64+
result.html()
65+
.then(html => {
66+
let headers = result.headers;
67+
let statusMessage = result.error ? 'NOT OK ' : 'OK ';
68+
69+
for (var pair of headers.entries()) {
70+
res.set(pair[0], pair[1]);
71+
}
72+
73+
if (result.error) {
74+
log("RESILIENT MODE CAUGHT:", result.error.stack);
75+
next(result.error);
76+
}
77+
78+
log(result.statusCode, statusMessage + path);
79+
res.status(result.statusCode);
80+
res.send(html);
81+
})
82+
.catch(error => {
83+
res.status(500);
84+
next(error);
85+
});
86+
}
6287
}
6388

6489
function failure(error) {

0 commit comments

Comments
 (0)