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

hapi-405-routes

v0.7.1

Published

Allows 405 'Method Not Allowed' responses for hapi routes

Downloads

10

Readme

Hapi-405-Routes

Build Status

Plugin for Hapi.js to include 405 Method Not Allowed Responses on routes for a given set of methods.

Overview

This plugin registers additional routes with your hapi service for routes with specific methods not implemented.

Say you have a farming web service has an api with only 2 routes:

GET /farm/goats // route which retrieves data about all goats on the farm.
POST /farm/goats // route which allows for creation of additional goats.

By default, hapi responds with a 404 if there is not route/method match registered with the service. If a user were to request OPTIONS /farm/goats they would get a 404 response.

This plugin builds additional routes based on the route paths already implemented which will respond with a 405 status code. Using this plugin and requesting OPTIONS /farm/goats will respond with a 405 Method Not Allowed.

Additionally the 405 routes can be configured to respond with an allow header specifying which methods are allowed for the requested route path. See [options](# Options) below.

Installing

This plugin is available through an npm module.

npm install hapi-405-routes

Usage

This plugin must be registered after the implemented routes have already been registered with the service.

// my service routes
server.route(routes);

// this 405 route plugin
server.register([
    {
        register: require('hapi-405-routes'),
        options: {
            methodsToSupport: ['GET', 'DELETE', 'PATCH', 'POST', 'OPTIONS'],
            setAllowHeader: true,
            log: true
        }
    }
]);

Options

This plugin supports 4 options passed in during plugin registration: methodsToSupport, setAllowHeader, allowHeadWithGet, and log.

methodsToSupport

  • Data Type: Array<String>
  • Defaults: ['GET', 'POST', 'DELETE', 'PUT', 'PATCH', 'OPTIONS', 'TRACE']
  • Description: This option specifies which methods should respond with a 405 status code: "Method Not Allowed" if not already implemented.

log

  • Data Type: Boolean
  • Defaults: false
  • Description: Enables plugin logging

setAllowHeader

  • Data Type: Boolean
  • Defaults: false
  • Description: Sets an allow header with each 405 response containing the methods implemented for the related route path.

allowHeadWithGet

  • Data Type: Boolean
  • Defaults: false
  • Description: Includes HEAD with the allow header if a GET method is implemented for the related route path. (Hapi does not natively support HEAD methods)