Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hapi-405-routes

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hapi-405-routes

Allows 405 'Method Not Allowed' responses for hapi routes

  • 0.7.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
increased by100%
Maintainers
1
Weekly downloads
 
Created
Source

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)

FAQs

Package last updated on 02 May 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc