# @charlietango/msw-fastify-middleware

> Create a middleware for MSW to use with [Fastify](https://www.fastify.io/).

Latest version **3.1.0** (published 2024-02-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install @charlietango/msw-fastify-middleware
pnpm add @charlietango/msw-fastify-middleware
yarn add @charlietango/msw-fastify-middleware
bun add @charlietango/msw-fastify-middleware
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.1.0 |
| Published | 2024-02-09 |
| First published | 2023-01-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 9.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Charlie Tango |
| Maintainers | thebuilder, frederik_bosch |

## Links

- npm: https://www.npmjs.com/package/@charlietango/msw-fastify-middleware
- npm.io page: https://npm.io/package/@charlietango/msw-fastify-middleware

## Dependencies (3)

- [headers-polyfill](https://npm.io/package/headers-polyfill.md) ^4.0.2
- [@mswjs/interceptors](https://npm.io/package/@mswjs/interceptors.md) ^0.25.7
- [strict-event-emitter](https://npm.io/package/strict-event-emitter.md) 0.5.1

## Recent versions

- 3.1.0 (latest) — 2024-02-09
- 3.0.0 — 2023-12-07
- 2.0.2 — 2023-02-27
- 2.0.1 — 2023-02-27
- 2.0.0 — 2023-02-09
- 1.0.1 — 2023-01-06
- 1.0.0 — 2023-01-06

## README

# @charlietango/msw-fastify-middleware

Create a middleware for MSW to use with [Fastify](https://www.fastify.io/).

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

```js
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.

---
_Source: https://npm.io/package/@charlietango/msw-fastify-middleware · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
