Skip to content

Commit

Permalink
refactor: msw path 정규표현식을 사용하여 추출하도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
gxxrxn committed Dec 29, 2023
1 parent 9794276 commit 42ec55f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion .storybook/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@ const serviceApi = (path: string) =>

initialize({}, [
rest.get(nextApi('/service-api/*'), async (req, res, ctx) => {
const [_, path] = req.url.pathname.split('/service-api');
const { pathname } = req.url;
const match = /\/service-api(?<path>.*)/g.exec(pathname);

if (!match || !match.groups || !match.groups.path) {
return res(ctx.status(404, 'Invalid Request URL'));
}

const { path } = match.groups;
const originResponse = await ctx.fetch(serviceApi(`/api${path}`));
const originResponseData = await originResponse.json();

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,4 @@
"msw": {
"workerDirectory": "public"
}
}
}

0 comments on commit 42ec55f

Please sign in to comment.