diff --git a/src/instrumentation.ts b/src/instrumentation.ts index 4e7671e3..f0a1c6e7 100644 --- a/src/instrumentation.ts +++ b/src/instrumentation.ts @@ -6,9 +6,9 @@ export async function register() { ); if (process.env.NEXT_RUNTIME === 'nodejs') { - console.log('MOCKING ENABLED FOR:', process.pid); - const { server } = await import('@/src/mocks/node'); - server.listen(); + server.listen({ + onUnhandledRequest: 'bypass', + }); } } diff --git a/src/mocks/MSWComponent.tsx b/src/mocks/MSWComponent.tsx index d53252df..e4e7f81c 100644 --- a/src/mocks/MSWComponent.tsx +++ b/src/mocks/MSWComponent.tsx @@ -9,8 +9,7 @@ export const MSWComponent = ({ children }: { children: React.ReactNode }) => { useEffect(() => { if (!isInit) { - initMsw(); - isSetInit(true); + initMsw().then(() => isSetInit(true)); } }, [isInit]); diff --git a/src/mocks/handlers/post.ts b/src/mocks/handlers/post.ts index acef851c..1be54f74 100644 --- a/src/mocks/handlers/post.ts +++ b/src/mocks/handlers/post.ts @@ -1,6 +1,6 @@ import { HttpResponse, http } from 'msw'; -const getPostList = http.get(`${process.env.NEXT_DOMAIN}/posts`, () => { +const getPostList = http.get(`${process.env.NEXT_PUBLIC_URL}/posts`, () => { return HttpResponse.json({ content: [ { diff --git a/src/mocks/initMsw.ts b/src/mocks/initMsw.ts index 87b5c900..1b3939ed 100644 --- a/src/mocks/initMsw.ts +++ b/src/mocks/initMsw.ts @@ -1,19 +1,8 @@ -export const initMsw = () => { - if (process.env.NODE_ENV === 'development') { - if (process.env.NEXT_RUNTIME === 'nodejs') { - (async () => { - const { server } = await import('./node'); - server.listen({ - onUnhandledRequest: 'bypass', - }); - })(); - } else { - (async () => { - const { worker } = await import('./browser'); - worker.start({ - onUnhandledRequest: 'bypass', - }); - })(); - } +export const initMsw = async () => { + if (process.env.NEXT_RUNTIME !== 'nodejs') { + const { worker } = await import('./browser'); + await worker.start({ + onUnhandledRequest: 'bypass', + }); } };