NET 6.0 React SPA template - consider adding an onError handler to setupProxy.js to prevent websocket connection crashes #35155
Comments
|
@JakeYallop thanks for contacting us. Your suggestion sounds appropriate. Is there a way to add the error handling globally or does it have to be within an endpoint? Also, we would gladly accept a PR for this if you are willing to contribute it. We've moved the spa templates to here |
|
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process. |
|
There isn't really a way to set global options - all we're really doing when we call |
|
@JakeYallop I apologize, I didn't express myself correctly. I meant if we can do it here as a one time thing, or if we need to do it on a per endpoint basis. At least the function to handle the errors should be defined in one place, that's all I'm asking for. |
|
Ah - yep, that's totally possible - we don't need to add error handling per endpoint. |
The problem
The new NET 6.0 React SPA template uses the http-proxy-middleware package to proxy http requests from the React dev server to ASP Net Core.
If a project uses websockets, these need to be proxied in a specific way:
Unfortunately, whenever the backend webserver is restarted, it causes the react dev server to crash due to the websocket connection no longer being available and throwing an error:
Which means you now need to recompile your entire front-end application whenever you restart the backend webserver. This is quite slow and effects the inner-loop significantly, especially for larger apps.
Proposed solution
Checking the documentation for http-proxy-middleware, we can pass an
onErrorhandler to it to handle any exceptions:This stops the dev server from crashing outright:
I propose adding this error handler to the proxy defined in ./src/setupProxy.js by default, to improve the inner-loop for new developers.
This file is already something that may need to edited manually by developers as they add new API endpoints, so adding an error handler that may also want to modify isn't a huge leap.
The text was updated successfully, but these errors were encountered: