{"id":18552376,"url":"https://github.com/traviswimer/hapi-route-hierarchy","last_synced_at":"2025-05-15T11:12:49.570Z","repository":{"id":57141604,"uuid":"72699960","full_name":"traviswimer/hapi-route-hierarchy","owner":"traviswimer","description":"Hapi plugin that automatically sets up your routes based on your directory hierarchy.","archived":false,"fork":false,"pushed_at":"2017-11-20T04:09:49.000Z","size":12,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-15T11:12:40.660Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/traviswimer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-MIT","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-11-03T02:14:44.000Z","updated_at":"2016-11-03T02:15:52.000Z","dependencies_parsed_at":"2022-09-03T07:40:35.614Z","dependency_job_id":null,"html_url":"https://github.com/traviswimer/hapi-route-hierarchy","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/traviswimer%2Fhapi-route-hierarchy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/traviswimer%2Fhapi-route-hierarchy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/traviswimer%2Fhapi-route-hierarchy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/traviswimer%2Fhapi-route-hierarchy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/traviswimer","download_url":"https://codeload.github.com/traviswimer/hapi-route-hierarchy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254328389,"owners_count":22052633,"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":[],"created_at":"2024-11-06T21:14:02.183Z","updated_at":"2025-05-15T11:12:44.561Z","avatar_url":"https://github.com/traviswimer.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# hapi-route-hierarchy\n\n\u003e Hapi plugin that automatically sets up your routes based on your directory hierarchy.\n\n## What is this?\n\nThe purpose of this plugin is to allow intuitive route setup by basing routes on your directory structure. For example, imagine you have a Hapi project with this folder structure:\n\n```\nmy_hapi_project\n│   server.js\n│\n└───routes\n    │   login.js\n    │\n    └───users\n        │   group_a.js\n        │   group_b.js\n```\n\nAssume that `server.js` simply starts the Hapi server, after registering the plugin like this:\n\n```javascript\nserver.register(\n    {\n        plugin: require( 'hapi-route-hierarchy' ),\n        options: {\n            root: __dirname + '/routes',\n            glob_pattern: '**/*.js'\n        }\n    }, ( err ) =\u003e {\n        // Start the server...\n    }\n)\n```\n\nAll the files under `/routes` include the data for all the routes. So for example, `/routes/login.js` might look like this:\n\n```javascript\nmodule.exports = {\n    method: 'GET',\n    path: '/login',\n    handler: function( request, h ) {\n        return h.response( 'You have been authenticated!' );\n    }\n};\n```\n\nThis will result in a route at `/login`, which is rather boring, but what if we put something similar in `/routes/users/group_a.js`:\n\n```javascript\nmodule.exports = {\n    method: 'GET',\n    path: '/group_a',\n    handler: function( request, h ) {\n        return h.response( 'Here is a list of all users in group A!' );\n    }\n};\n```\n\nThis would result in a route at `/users/group_a`.\n\nIn this way you can easily keep your routes organized by ensuring they always match your directory structure.\n\n## Plugin Options\n\n### root\n\n- **REQUIRED**\n- Type: `string`\n- Description: The directory to search for files with route data. This can accept 2 types of paths:\n\n  - Relative path from `process.cwd()`\n  - Absolute path\n\n### glob_pattern\n\n- **REQUIRED**\n- Type: `string`\n- Description: The [glob](https://www.npmjs.com/package/glob) pattern to use to determine which files should be loaded as route files.\n\n### glob_options\n\n- Type: `object`\n- Description: Options that will be passed to the `glob` NPM module. Here is a [full list of available options](https://www.npmjs.com/package/glob#options).\n\n## Route files\n\nThe route files can define route data in 3 different ways:\n\n### Object\n\n```javascript\nmodule.exports = {\n    method: 'GET',\n    path: '/some_path',\n    handler: function( request, h ) {\n        // Do something...\n    }\n};\n```\n\n### Array\n\n```javascript\nmodule.exports = [\n    {\n        method: 'GET',\n        path: '/some_path',\n        handler: function( request, h ) {\n            // Do something...\n        }\n    },\n    {\n        method: 'POST',\n        path: '/some_other_path',\n        handler: function( request, h ) {\n            // Do something...\n        }\n    }\n];\n```\n\n### Function\n\n*Note that this variation allows you to access the Hapi server object*\n\n```javascript\nmodule.exports = function( server ){\n    return {\n        method: 'GET',\n        path: '/some_path',\n        handler: function( request, h ) {\n            let some_fancy_plugin = request.server.plugins['some_fancy_plugin'];\n            h.response( some_fancy_plugin.doFancyThings() );\n        }\n    };\n};\n```\n\n## Contributing\n\nIn lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftraviswimer%2Fhapi-route-hierarchy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftraviswimer%2Fhapi-route-hierarchy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftraviswimer%2Fhapi-route-hierarchy/lists"}