npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

better-fastify-405

v0.2.0

Published

A better plugin for handling 405 in Fastify

Downloads

13

Readme

Better Fastify 405

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

Maintainability Codacy Badge Test Coverage

Why do I need this?

By default Fastify suppress error 405 and with return 404 instead. A 405 error would improve the development experience.

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

npm add better-fastify-405
yarn add better-fastify-405

Usage

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

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
})