Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I implement MSW in a NextJS backend? #2136

Closed
moonman239 opened this issue Apr 19, 2024 · 0 comments
Closed

How do I implement MSW in a NextJS backend? #2136

moonman239 opened this issue Apr 19, 2024 · 0 comments

Comments

@moonman239
Copy link

I'm new to MSW and have been trying to get MSW to intercept "fetch" requests that my NextJS app backend makes to a third-party API. I have my handlers & server set up already, and I have imported my server code into an API endpoint (so according to my logs, MSW must be listening whenever I trigger the endpoint after running "npm run dev") According to instructions, this is probably where said code should be imported.

However, it appears that my requests are all being "bypassed" without warning, despite me configuring MSW to emit a warning if it receives a request that it cannot handle, so debugging is pretty hard.

The server is initialized like so:

\\ listen.ts
import { server } from './msw_server';

server.listen({
    onUnhandledRequest:'warn'
});

and set up like so:

\\msw_server.ts
import { setupServer } from 'msw/node'
import { handlers } from './msw_handlers';
 
export const server = setupServer(...handlers)

and imported like so in the API endpoint:

import "../mockServiceWorker/listen.ts"
@mswjs mswjs locked and limited conversation to collaborators Apr 20, 2024
@kettanaito kettanaito converted this issue into discussion #2137 Apr 20, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant