Skip to content

Running MSW in SSR apps #1209

Answered by kettanaito
nareshbhatia asked this question in Q&A
Apr 17, 2022 · 2 comments · 7 replies
Discussion options

You must be logged in to vote

Hey, @nareshbhatia.

Can MSW also be used to mock APIs that are called from the server-side on frameworks such as Next.js and Remix? How does this conceptually work?

Yes, that's possible. You can see the Next.js usage example where the same mocks are used for the client- and server-side requests.

What if my app makes calls from both client-side and server-side?

Your app can make requests from both sides and still get them intercepted. This is achieved by different interceptors though—you use setupWorker in the client and setupServer in the server process.

Limitations

There are, however, limitations to this approach. As you instantiate interception in different environments, there's no …

Replies: 2 comments 7 replies

Comment options

You must be logged in to vote
5 replies
@nareshbhatia
Comment options

@alexanderkrust
Comment options

@kettanaito
Comment options

@willscott085
Comment options

@Lewischarlton93
Comment options

Answer selected by nareshbhatia
Comment options

You must be logged in to vote
2 replies
@kettanaito
Comment options

@tehandyb
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
6 participants