Install
npm install msw --save-dev npm install encoding --save-dev
Run from command line
npx msw init static --save
The files msw.client.js, msw-server.js go in ~/plugins.
My directory layout:
~/api/ ~/api/msw/ ~api/msw/browser.js ~api/msw/server.js ~/api/msw/api/ ~/api/msw/api/index.ts
MSW does not appear to play well with the use of nuxt server and whatever helpful things it does for you under the hood. I don't really understand nuxt, so it is possible that someone more knowledgeable about nuxt might be able to get the two to cooperate.
I use fetch, not $fetch = ohmyfetch; ohmyfetch tries to be more helpful than I prefer.
I'm running exactly into this. I'm using
$fetch
because I can intercept requests easily to refresh the JWT... but it brings other issues. Ugh. Maybe I should just stick to fetch.Thanks for putting this out here btw. I landed on a similar solution, but using
if (typeof window === 'undefined') {
instead of naming the files.client.
/.server.