# better-fastify-405

> A better plugin for handling 405 in Fastify

Latest version **0.2.0** (published 2021-03-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install better-fastify-405
pnpm add better-fastify-405
yarn add better-fastify-405
bun add better-fastify-405
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2021-03-30 |
| First published | 2021-03-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 6.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Hugo Sum |
| Maintainers | johnwinston0410 |
| Keywords | fastify, fastify-plugin, fastify-405 |

## Links

- npm: https://www.npmjs.com/package/better-fastify-405
- Repository: https://github.com/winston0410/better-fastify-405
- npm.io page: https://npm.io/package/better-fastify-405

## Recent versions

- 0.2.0 (latest) — 2021-03-30
- 0.1.2 — 2021-03-29
- 0.1.1 — 2021-03-29
- 0.1.0 — 2021-03-29

## README

# Better Fastify 405

A simple and fully customizable Fastify plugin for handling 405 gracefully.

[![Maintainability](https://api.codeclimate.com/v1/badges/23557cfcd9416cc4f098/maintainability)](https://codeclimate.com/github/winston0410/better-fastify-405/maintainability) [![Codacy Badge](https://app.codacy.com/project/badge/Grade/a88113b4d6ac4acbb90be5864aacae27)](https://www.codacy.com/gh/winston0410/better-fastify-405/dashboard?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=winston0410/better-fastify-405&amp;utm_campaign=Badge_Grade) [![Test Coverage](https://api.codeclimate.com/v1/badges/23557cfcd9416cc4f098/test_coverage)](https://codeclimate.com/github/winston0410/better-fastify-405/test_coverage)

## Why do I need this?

By default [Fastify suppress error 405](https://github.com/fastify/fastify/issues/917) and with return 404 instead. A 405 error would improve the development experience.

[fastify-405](https://github.com/Eomm/fastify-405) was built to solve this issue, but it requires you to input a RegExp for the route you want to handle 405.

This plugin is meant to read from your current route setting, and create routes that return 405 automatically.

## Installation

```shell
npm add better-fastify-405
```

```shell
yarn add better-fastify-405
```

## Usage

```javascript
//app.js
import fastify, { FastifyRequest, FastifyReply, FastifyInstance, HookHandlerDoneFunction, RouteOptions } from 'fastify';

const app: FastifyInstance = fastify({
  logger: true
})

//Other plugins
app.register(import("fastify-etag"))
app.register(import('plugins/better-fastify-405'), {
  routes: [
    //Required.
		//Register all your route here, or else this plugin would not work.
    import('./routes/index'),
    import('./routes/protected')
		//All the route will be registered inside the plugin. Do not use app.register() here.
  ],
  filterCallback: ({ route, method }) => {
    // Optional
    // A callback to allow you filter out specific route and specific method from assigning it to 405

    //Route: route registered
    //Method: method available to apply 405
    return true
  }
})
```

### Do not mark `OPTIONS` route with 405

A function `allowCORS` is provided to help you not mark `OPTIONS` for 405.

```javascript
import better405, { allowCORS } from 'better-fastify-405'

import fastify, { FastifyRequest, FastifyReply, FastifyInstance, HookHandlerDoneFunction, RouteOptions } from 'fastify';

const app: FastifyInstance = fastify({
  logger: true
})

//Other plugins
app.register(import("fastify-etag"))
app.register(better405, {
  routes: [
    import('./routes/index'),
    import('./routes/protected')
  ],
  filterCallback: allowCORS
})
```

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