Question/Feature request: Is there a way to run msw independently from the frontend app? #1040
-
Is your feature request related to a problem? Please describe. I am thinking: why going into this trouble when I can have the mock server completely detached from the frontend app? Describe the solution you'd like
Describe alternatives you've considered Additional context |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hey, @flowck. Thanks for raising this. It'd be great to improve the recipe to rely on patterns you can use in any framework/setup, no matter how abstracted. Like with NextJS, where you don't control the application mounting directly.
Devising this deferred rendering pattern may seem like a chore but it's insignificant compared to the cost of writing and running a standalone server, even if for the local development. On top of that, there are other things that a mocked server implies, such as routing all your requests to that server just for the sake of development/testing. This diverges your app and opens room for mistakes. We do support running an HTTP server via @mswjs/http-middleware but I strongly discourage you from doing so, as yours isn't the use case we've designed the said package. What I think should happen here is for the library to provide a simple and reliable way to intercept requests made on the initial mounting of components (compensating or removing the race condition between the worker registration and the app mounting). We are open to ideas as our current approach (buffering all requests and postponing them until the worker is ready) clearly doesn't work for quite a few people. |
Beta Was this translation helpful? Give feedback.
Hey, @flowck. Thanks for raising this.
It'd be great to improve the recipe to rely on patterns you can use in any framework/setup, no matter how abstracted. Like with NextJS, where you don't control the application mounting directly.
Devising this deferred rendering pattern may seem like a chore but it's insignificant compared to the cost of writing and running a standalone server, even if for the local development. On top of that, there are other things that a mocked server implies, such as routing all your requests to that server just for the sake of development/testin…