aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--vnext/server/middleware/renderer.js11
1 files changed, 9 insertions, 2 deletions
diff --git a/vnext/server/middleware/renderer.js b/vnext/server/middleware/renderer.js
index e7ed3337..f60aa23c 100644
--- a/vnext/server/middleware/renderer.js
+++ b/vnext/server/middleware/renderer.js
@@ -34,21 +34,28 @@ const serverRenderer = async (req, res, next) => {
const marker = '<div id="app">';
const data = htmlData.split(marker);
const propsData = `<script>window.__PROPS__="${Buffer.from(JSON.stringify(props)).toString('base64')}";</script>${marker}`;
+ let didError = false;
const { pipe } = ReactDOMServer.renderToPipeableStream(
<StaticRouter location={req.baseUrl} context={routerContext}>
<App {...props} />
</StaticRouter>
, {
onShellReady() {
+ res.statusCode = didError ? 500 : 200;
+ res.setHeader('Content-type', 'text/html');
+ res.write(data[0]);
+ res.write(propsData);
pipe(res, { end: false });
},
onAllReady() {
res.write(data[1]);
res.end();
+ },
+ onError(err) {
+ didError = true;
+ console.log(err);
}
});
- res.write(data[0]);
- res.write(propsData);
});
};