
Security News
PodRocket Podcast: Inside the Recent npm Supply Chain Attacks
Socket CEO Feross Aboukhadijeh discusses the recent npm supply chain attacks on PodRocket, covering novel attack vectors and how developers can protect themselves.
fastify-405
Advanced tools
Add 405 Method Not Allowed HTTP status to your routes, instead of the default 404.
npm install fastify-405
Plugin version | Fastify version |
---|---|
^4.0.0 | ^5.0.0 |
^3.0.0 | ^4.0.0 |
^2.0.0 | ^3.2.0 |
^1.0.0 | ^2.0.0 |
Register the plugin with some custom option.
It will add an onRoute
hook and will add an handler
that replay with HTTP status 405 and the allow
response header.
The allow
header will contains what you define in the options.
This plugin has been tested also with the encapsulation!
import Fastify from 'fastify'
const fastify = Fastify()
await fastify.register(import('fastify-405'), {
regexp: /\/foo.*/,
allow: ['GET', 'HEAD']
})
// This route will reply 405 on POST, HEAD, OPTIONS, PUT..
fastify.get('/foo', (req, reply) => {
reply.send({ hello: 'world' })
})
// This route will not match the fastify-405 regexp and will reply with 404 on other HTTP methods
fastify.get('/bar', (req, reply) => {
reply.send({ hello: 'world' })
})
await fastify.listen({ port: 3000 })
console.log('Server listening at http://localhost:3000')
Note You need to
await
the plugin registration to make sure the plugin is ready to use. All the routes defined before the plugin registration will be ignored. This change has been introduced in Fastify v4.
You can pass the following options during the registration:
Option | Default | Description |
---|---|---|
regexp | /.*/ | The regular expression the route must fulfil in order to add the 405 handler |
allow | ['GET', 'POST'] | The method that the route will allow, the HTTP methods that are not in this array will reply 405 |
await fastify.register(require('fastify-405'), {
regexp: /\/foo.*/, // must be a regular expression
allow: ['GET', 'POST'] // could be only a subset of: ['GET', 'POST', 'HEAD', 'PUT', 'DELETE', 'OPTIONS', 'PATCH']
})
Copyright Manuel Spigolon, Licensed under MIT.
FAQs
Add 405 HTTP status to your routes
The npm package fastify-405 receives a total of 6 weekly downloads. As such, fastify-405 popularity was classified as not popular.
We found that fastify-405 demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Socket CEO Feross Aboukhadijeh discusses the recent npm supply chain attacks on PodRocket, covering novel attack vectors and how developers can protect themselves.
Security News
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
Product
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.