@charlietango/msw-fastify-middleware
TypeScript icon, indicating that this package has built-in type declarations

3.1.0 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i @charlietango/msw-fastify-middleware

Weekly Downloads

22

Version

3.1.0

License

MIT

Unpacked Size

9.96 kB

Total Files

8

Last publish

Collaborators

  • thebuilder
  • frederik_bosch