{"id":15285688,"url":"https://github.com/alepouna/fastify-router","last_synced_at":"2025-10-07T01:30:16.514Z","repository":{"id":225075918,"uuid":"568112490","full_name":"alepouna/fastify-router","owner":"alepouna","description":"A simple Fastify router and loader for Fastify servers.","archived":true,"fork":false,"pushed_at":"2024-02-29T04:55:42.000Z","size":33,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-19T19:58:50.430Z","etag":null,"topics":["fastify","router"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alepouna.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null},"funding":{"github":null,"patreon":null,"open_collective":null,"ko_fi":"auroraisluna","tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2022-11-19T13:46:49.000Z","updated_at":"2024-02-29T04:55:51.000Z","dependencies_parsed_at":"2024-02-29T05:48:31.669Z","dependency_job_id":null,"html_url":"https://github.com/alepouna/fastify-router","commit_stats":null,"previous_names":["alepouna/fastify-router","auroraisluna/fastify-router"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alepouna%2Ffastify-router","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alepouna%2Ffastify-router/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alepouna%2Ffastify-router/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alepouna%2Ffastify-router/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alepouna","download_url":"https://codeload.github.com/alepouna/fastify-router/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235569500,"owners_count":19011184,"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","router"],"created_at":"2024-09-30T15:07:09.931Z","updated_at":"2025-10-07T01:30:16.167Z","avatar_url":"https://github.com/alepouna.png","language":"JavaScript","funding_links":["https://ko-fi.com/auroraisluna","https://ko-fi.com/Y8Y1ACFQW"],"categories":[],"sub_categories":[],"readme":"## ⚠️⚠️⚠️ As of 29/02/2024 this repo has been moved to GitLab at https://gitlab.com/alepouna.dev/fastify-router\r\n\r\n# fastify-router\r\n\r\nA simple router loader for fastify servers. \r\n\r\nWarning, this is junky. But hey, if it works, don't fix it! (actual suggestions are welcome :p)\r\nPlease note I use this for my personal projects, its not meant to be fast, efficient or smart and certinaly wasn't designed to be used in production. I created this so I don't have to setup routes with every new webserver I create and I couldn't find anything on fastify that did this. It saves time :D  \r\n\r\nRead through this entire document for instructions on how to use this!  \r\n\r\n## Installation\r\n\r\nInstall via NPM (https://www.npmjs.com/package/fastifyrouter.js)\r\n`npm i fastifyrouter.js`\r\n\r\n## Use\r\n\r\nHere's how to use this tool\r\n\r\n### On your webserver setup file\r\n\r\nCall the loadRoutes function, inject fastify and options and voila!\r\n```js\r\nimport { loadRoutes } from '/path/to/index.mjs'\r\n//or from npm\r\nimport { loadRoutes } from 'fastifyrouter.js';\r\n\r\n//Example fastify server \r\nimport Fastify from 'fastify';\r\nconst fastify = Fastify();\r\n\r\nawait loadRoutes(fastify, { dir: './src/routes/', log: true, method: 'GET', prefix: '/home' });\r\n```\r\n\r\n#### Options: \r\n\r\n- dir: the directory of all the routes you want to load, its using the current module dir so if the module is in `node_modules/blah` and your routes in `src/routes`, you will have to set it as `../src/routes`\r\n- log: log to console some debug/verbose messages [optional]\r\n- method: which method to use as a default (if one not defined in the file name) [optional]\r\n- prefix: add a prefix to the path. if you are using a folder organization structure, the prefix will not be included by default, so we add this option to mitage this (see issue #3)\r\n\r\n### On your route file\r\n\r\nExport a default (async) function with two properties: request \u0026 reply (as fastify does)\r\n\r\n```js\r\nexport default async function (request, reply) {\r\n    return reply.send({ hello: 'world' });\r\n};\r\n```\r\n\r\n### Paths, params, queries, etc (Folder structure)\r\n \r\nI basically go by the principal that the folder path is also your path. files named `index` will be treated as the end/trail of that path. \r\nSo if you want to render the page `/path/to/page` you will have a folder structure of `/src/routes/path/to/page/index.js` or `/src/routes/path/to/page.js` depends on how you want to organize things :) \r\n\r\nFor params, because on windows you can't use `:` for file names instead I do `[]`. So lets say you have param `people` you will define it in a path like this: \r\n`/path/to/[people]/index.js` -\u003e /path/to/:people/\r\n\r\nQueries are handled by fastify already, you don't have to do special definitions. \r\n\r\n#### But what about REST? \r\nAll routes MUST contain the rest method in the file name, followed by a `-` and the path. example: `GET-index.js`, `POST-index.js`, `SET-index.js` etc. \r\nIf the a method does NOT contain one, it will use the default method you set in the options. (if none is set, it will use `GET`)\r\nI can not verify if `ANY`/`ALL` works, as my results are inconclusive. If you can replicate/use, please make an issue request so I can remove this statement :)  \r\n\r\n## Contributing: \r\n- By code: Make a pr! Add comments to your code and have proper variable names!\r\n- By suggestions/bugs: Make an issue request! Have as many details as you can so I can replicate and fix! \r\n- By donating: [![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/Y8Y1ACFQW) \r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falepouna%2Ffastify-router","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falepouna%2Ffastify-router","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falepouna%2Ffastify-router/lists"}