일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 인터섹션
- 결정 알고리즘
- Promise
- CORS
- RTK Query
- 이분 검색
- 타입 좁히기
- webpack
- React
- autosize
- 반공변성
- 호이스팅
- ESlint
- app router
- async/await
- tailwind
- Jest
- useAppDispatch
- dfs
- 태그된 유니온
- 리터럴 타입
- 무한 스크롤
- CI/CD
- map
- 공변성
- recoil
- SSR
- Cypress
- 투포인터
- TS
Archives
- Today
- Total
짧은코딩
MSW1 사용 중 Warning: captured a request without a matching request handler 본문
wayc 이커머스 프로젝트
MSW1 사용 중 Warning: captured a request without a matching request handler
5_hyun 2024. 1. 3. 16:48반응형
MSW를 사용하여 개발하는데, 콘솔에 이런 경고 메시지가 엄청 많이 떴다.
콘솔 로그를 보면서 테스트를 진행해야 하는데 불편함이 생겨서 저 경고 메시지를 없애보려고 한다.
왜 저런 경고가 뜨는걸까?
- MSW의 worker가 API를 가로채서 mock 데이터를 보내주는 것인데
- 정의되지 않은 주소를 가로챘기 때문에 발생한다.
- 따라서 요청에서 무시하거나 허용하는 onUnhandledRequest를 사용하여 지정해야한다.
해결법
onUnhandledRequest
이 속성은 setupWorker 초기화 이후에 Request handler를 등록하기 위해 사용된다.
https://mswjs.io/docs/api/setup-worker/start#onunhandledrequest
자세한걸 보고싶으면 공식 문서로 가보는 것이 좋겠다.
코드
// once the Service Worker is up and ready to intercept requests.
return worker.start({
onUnhandledRequest(req, print) {
const allowedDomain = "https://loremflickr.com/";
const allowedDomain2 = "https://picsum.photos/";
const allowedDomain3 = " https://fonts.gstatic.com";
if (
req.url.pathname.startsWith("/public/") ||
req.url.pathname.startsWith("/slideImage/") ||
req.url.pathname.startsWith("/dist/") ||
req.url.href.startsWith(allowedDomain) ||
req.url.href.startsWith(allowedDomain2) ||
req.url.href.startsWith(allowedDomain3)
) {
return;
}
print.warning();
},
});
이렇게 폴더와 도메인에 대해 허용하여 warning이 뜨는 것을 방지했다.
반응형
'wayc 이커머스 프로젝트' 카테고리의 다른 글
무한 스크롤 값 저장 방식 수정 with 공식 사이트 (0) | 2024.01.08 |
---|---|
스크롤 맨 위로 올리기 with react-custom-scrollbars (1) | 2024.01.07 |
전체 상품 불러오기 무한 스크롤 구현 with react-intersection-observer (0) | 2023.12.26 |
Webpack의 HMR과 자동 새로고침 현상 (0) | 2023.11.12 |
로그인 전략 with Cookie (0) | 2023.10.24 |
Comments