{"id":23256542,"url":"https://github.com/imedadel/fastify-autoroute","last_synced_at":"2026-04-18T02:32:46.196Z","repository":{"id":57233265,"uuid":"292909063","full_name":"imedadel/fastify-autoroute","owner":"imedadel","description":"Next.js file routing for Fastify","archived":false,"fork":false,"pushed_at":"2020-09-05T00:07:13.000Z","size":87,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-09T17:51:24.752Z","etag":null,"topics":["fastify","fastify-plugin","nextjs","router"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/fastify-autoroute","language":"TypeScript","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/imedadel.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-09-04T17:33:52.000Z","updated_at":"2020-09-05T00:07:15.000Z","dependencies_parsed_at":"2022-08-31T20:51:12.956Z","dependency_job_id":null,"html_url":"https://github.com/imedadel/fastify-autoroute","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/imedadel/fastify-autoroute","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imedadel%2Ffastify-autoroute","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imedadel%2Ffastify-autoroute/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imedadel%2Ffastify-autoroute/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imedadel%2Ffastify-autoroute/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/imedadel","download_url":"https://codeload.github.com/imedadel/fastify-autoroute/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imedadel%2Ffastify-autoroute/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263244729,"owners_count":23436478,"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","nextjs","router"],"created_at":"2024-12-19T12:17:17.351Z","updated_at":"2026-04-18T02:32:46.157Z","avatar_url":"https://github.com/imedadel.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Fastify AutoRoute\n\n\u003e Next.js file routing for Fastify.\n\nIf you're familiar with Next.js, you know how awesome the routing is. If not, have a look on their [documentation](https://nextjs.org/docs/routing/dynamic-routes) :)\n\nAutoRoute gives you exactly the same routing (except for optional catch all routes, they can't be done in Fastify or they're inherently supported, _je sais pas_ 🤷‍♀️).\n\n# Install\n\n```shell\nyarn add fastify-autoroute\n# or\nnpm i fastify-autoroute\n```\n\n# Usage\n\nAdd AutoRoute as a plugin to Fastify:\n\n```ts\nimport { FastifyPlugin } from \"fastify\";\nimport { join } from \"path\";\nimport fastifyAutoRoute from \"fastify-autoroute\";\n\nconst app: FastifyPlugin = function (fastify, opts, next): void {\n\tfastify.register(fastifyAutoRoute, {\n\t\tautoRouteDir: join(__dirname, \"routes\"),\n\t});\n\n\tnext();\n};\n\nexport default app;\n```\n\n# Options\n\n- **autoRouteDir** (required, string) — this is the root folder of your routes. This is similar to Next.js `/pages`.\n\n# Structure\n\n\u003e I tried explaining this, but instead here is an example\n\nFor the following directory:\n\n```\n├───routes\n│   ├───users\n│   │   ├───[id]\n│   │   │   ├───index.get.ts\n│   │   │   ├───index.delete.ts\n│   │   │   ├───name.get.ts\n│   │   │   └───email.get.ts\n│   │   └───index.post.ts\n│   ├───teams\n│   │   ├───[...slug].get.ts\n│   └───index.get.ts\n```\n\nYou will get the following Fastify routes:\n\n```\nGET\t/\nPOST\t/users\nGET\t/users/name\nGET\t/users/email\nGET\t/users/:id\nDELETE\t/users/:id\nGET\t/teams/*\n```\n\n**Note.** the method `all` is expanded into all the methods supported by Fastify.\nSo, `name.all.ts` is expanded into\n\n```\nGET /name\nPOST /name\nPUT /name\n...\n```\n\n# File content\n\nThe default export is passed as a `handler` to `fastify.route()`. All other named exports are bassed as options to `fastify.route()` too.\n\n```ts\nexport const schema = {};\nexport const onRequest = [];\nexport default async (request: FastifyRequest, reply: FastifyReply) =\u003e {\n\treturn { ok: true };\n};\n```\n\n## Accessing Fastify\n\nIn order to access Fastify and its decorators, you can use the following structure:\n\n```ts\nexport default (fastify: FastifyInstance) =\u003e async (\n\trequest: FastifyRequest,\n\treply: FastifyReply\n) =\u003e {\n\treturn {\n\t\tconfig: fastify.config,\n\t};\n};\n```\n\nThe same structure applies when accessing Fastify from inside `onRequest`:\n\n```ts\nexport const onRequest = [\n\t(fastify) =\u003e async (request, reply) =\u003e {\n\t\t// your content\n\t\treturn;\n\t},\n];\n```\n\nCurrently, accessing Fastify from inside other hooks is not supported.\n\n# Unresolved issues\n\n- **Typing:** Can't it be nicer? Like automatic typing for every exported function? Is that possible in Typescript?\n- **More errors:** There should be more errors and checks for when users misuse this plugin.\n\n# Author\n\nImed Adel ([Twitter](https://twitter.com/imedadel_))\n\n# License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimedadel%2Ffastify-autoroute","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimedadel%2Ffastify-autoroute","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimedadel%2Ffastify-autoroute/lists"}