{"id":15061703,"url":"https://github.com/gkampitakis/fastify-method-not-allowed","last_synced_at":"2026-01-02T09:13:18.491Z","repository":{"id":38211366,"uuid":"312776098","full_name":"gkampitakis/fastify-method-not-allowed","owner":"gkampitakis","description":"Fastify plugin handling method not allowed for routes","archived":false,"fork":false,"pushed_at":"2022-06-09T00:43:40.000Z","size":15,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-22T18:51:16.715Z","etag":null,"topics":["fastify","fastify-plugin","npm-package"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/fastify-method-not-allowed","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gkampitakis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-11-14T08:26:25.000Z","updated_at":"2023-06-16T16:19:20.000Z","dependencies_parsed_at":"2022-09-04T18:02:12.349Z","dependency_job_id":null,"html_url":"https://github.com/gkampitakis/fastify-method-not-allowed","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gkampitakis%2Ffastify-method-not-allowed","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gkampitakis%2Ffastify-method-not-allowed/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gkampitakis%2Ffastify-method-not-allowed/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gkampitakis%2Ffastify-method-not-allowed/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gkampitakis","download_url":"https://codeload.github.com/gkampitakis/fastify-method-not-allowed/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243723194,"owners_count":20337333,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fastify","fastify-plugin","npm-package"],"created_at":"2024-09-24T23:23:56.691Z","updated_at":"2026-01-02T09:13:18.461Z","avatar_url":"https://github.com/gkampitakis.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Fastify Method Not Allowed\n\n[![js-semistandard-style](https://img.shields.io/badge/code%20style-semistandard-brightgreen.svg)](https://github.com/standard/semistandard)\n\n`fastify-method-not-allowed` is a plugin for returning **405** status code for routes instead of default **404**.\n\nNote you have to register this plugin before registering any routes, as it uses [onRoute](https://www.fastify.io/docs/v3.7.x/Hooks/#onroute) hook, so needs to \"collect\" them.\n\n## Install\n\n```bash\nnpm install fastify-method-not-allowed\n```\n\n## Usage\n\nRequire the module and just register it as any other fastify plugin.\n\n```javascript\nconst methodNotAllowed = require('fastify-method-not-allowed');\n\nserver.register(methodNotAllowed);\n\nserver.get('/', (req, res) =\u003e res.send('Hello World'));\n\nfastify.listen(3000);\n\n/*\ncurl -X POST localhost:3000\n\nThis will return statusCode 405 instead of the 404 default response\n*/\n```\n\n## API\n\n### register plugin\n\n```javascript\nconst methodNotAllowed = require('fastify-method-not-allowed');\n\nserver.register(methodNotAllowed, {\n    responses: {\n        404: 'Not Found',\n        405: 'Method Not Allowed',\n    },\n});\n```\n\n### register options\n\n-   `prefix`: prefix on which path this plugin will be enabled\n    \u003cbr\u003e \u003cspan style=\"font-size:15px\"\u003e You can register the plugin multiple times with different prefixes if you want to apply different responses on different paths\u003cspan\u003e\n-   `responses`\n    \u003cbr\u003e \u003cspan style=\"font-size:15px\"\u003e Default values\u003cspan\u003e\n\n    -   404\n\n    ```json\n    {\n        \"message\": \"Route \u003cmethod\u003e:\u003curl\u003e not found\",\n        \"error\": \"Not Found\",\n        \"statusCode\": 404\n    }\n    ```\n\n    -   405\n\n    ```json\n    {\n        \"message\": \"Route \u003cmethod\u003e:\u003curl\u003e not allowed\",\n        \"error\": \"Method Not Allowed\",\n        \"statusCode\": 405\n    }\n    ```\n\n    You can override those values by providing either a **value** or a **function**.\n\n    -   For **404** you have access to the `request` object so you can pass a function e.g. `(req)=\u003e\"Route `\\${req.url}` not found\"`.\n    -   For **405** you have access to the `request` and `allowedMethods` so you can pass a function e.g. `(req,methods)=\u003e\"Route `\\${req.url}` allowed only ${methods}\"`.\n\n-   `setNotFoundHandlerOptions` You can pass options to fastify handler. [For more information](https://www.fastify.io/docs/latest/Server/#setnotfoundhandler).\n\n## Typescript\n\nIn order to use this plugin you need to enable the flag `\"esModuleInterop\": true` in `tsconfig.json`.\n\nthen you can import it\n\n```typescript\nimport methodNotAllowed from 'fastify-method-not-allowed';\n```\n\n### Note:\n\nThis plugin uses the `setNotFoundHandler` handler so you won't be able to re-use this handler in your own service at least with the same `prefix`.\n\n### Issues\n\nFor any [issues](https://github.com/gkampitakis/fastify-method-not-allowed/issues).\n\n## License\n\nMIT License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgkampitakis%2Ffastify-method-not-allowed","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgkampitakis%2Ffastify-method-not-allowed","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgkampitakis%2Ffastify-method-not-allowed/lists"}