@charlietango/msw-fastify-middleware
v3.1.0
Published
Create a middleware for MSW to use with [Fastify](https://www.fastify.io/).
Downloads
129
Readme
@charlietango/msw-fastify-middleware
Create a middleware for MSW to use with Fastify.
Usage with SSR Vite
Load the async handlers inside the server file. They will be reloaded on change, so you get the latest data on every request.
import { mswFastifyMiddleware } from '@charlietango/msw-fastify-middleware';
app.all(
"/api/*",
mswFastifyMiddleware(async () => {
const { handlers } = await vite.ssrLoadModule(
"./src/api/mocks/handlers.ts"
);
return handlers;
})
);
Params
handlers
Handlers Set the MSW request handlers. Either as an array, or as an async function that returns the handlers.handleRequestOptions
Options to pass to the MSW handleRequest function.