3.1.0 • Published 3 months ago

@charlietango/msw-fastify-middleware v3.1.0

Weekly downloads
-
License
MIT
Repository
-
Last release
3 months ago

@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.