Skip to content

Commit ebed78c

Browse files
committed
fix: prevent dev SSR server from crashing if front is ready before back-end
1 parent 6b2cbcb commit ebed78c

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/internals/webpack/build-webpack-client-watch.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,20 @@ if (HAS_PRERENDERING) {
2323
// No worries though, this only happens in dev mode with pre-rendering.
2424
// Only one server is launched in prod mode or without pre-rendering.
2525

26-
const proxy = httpProxy.createProxyServer();
27-
const preRenderingServer = `http://localhost:${PRERENDERING_PORT}`;
26+
const proxy = httpProxy.createProxyServer({
27+
// target the SSR server (which only outputs HTML in dev as we have the fileSystem)
28+
target: `http://localhost:${PRERENDERING_PORT}`,
29+
});
30+
31+
proxy.on('error', (err, req, res) => {
32+
res.set('Content-Type', 'text/plain');
33+
res.status(500).send('Proxy could not contact SSR server. Either it is booting or it crashed (check console).');
34+
});
2835

2936
preRenderingHandler = (req: $Request, res: $Response) => {
3037
logger.debug(`Got request for ${JSON.stringify(req.url)}. Not a static file - dispatching to server-side rendering.`);
3138

32-
return proxy.web(req, res, {
33-
target: preRenderingServer,
34-
});
39+
return proxy.web(req, res);
3540
};
3641

3742
// dispatch root route to pre-rendering rather than distributing index.html

0 commit comments

Comments
 (0)