{"id":18435380,"url":"https://github.com/restify/enroute","last_synced_at":"2025-04-07T19:32:15.336Z","repository":{"id":56425108,"uuid":"47289629","full_name":"restify/enroute","owner":"restify","description":"restify route specification via JSON","archived":false,"fork":false,"pushed_at":"2023-11-30T14:41:06.000Z","size":93,"stargazers_count":28,"open_issues_count":3,"forks_count":2,"subscribers_count":9,"default_branch":"main","last_synced_at":"2025-03-13T16:43:08.631Z","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/restify.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-12-02T21:27:24.000Z","updated_at":"2024-03-10T08:56:33.000Z","dependencies_parsed_at":"2023-02-08T18:25:25.561Z","dependency_job_id":"96253cd9-5312-4487-84ae-82f5e3b07484","html_url":"https://github.com/restify/enroute","commit_stats":{"total_commits":72,"total_committers":14,"mean_commits":5.142857142857143,"dds":0.5277777777777778,"last_synced_commit":"d69f0740ab5ece07f82838af3e9bd585ed30cf4e"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/restify%2Fenroute","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/restify%2Fenroute/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/restify%2Fenroute/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/restify%2Fenroute/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/restify","download_url":"https://codeload.github.com/restify/enroute/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247716422,"owners_count":20984238,"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-06T06:08:03.442Z","updated_at":"2025-04-07T19:32:15.329Z","avatar_url":"https://github.com/restify.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# restify-enroute\n[![NPM Version](https://img.shields.io/npm/v/restify-enroute.svg)](https://npmjs.org/package/restify-enroute)\n[![Build Status](https://github.com/restify/enroute/actions/workflows/test.yml/badge.svg)](https://github.com/restify/enroute/actions/workflows/test.yml)\n\nThis module provides configuration driven route installation for restify.\nInstead of having to declare routes in code, you can create a configuration file\nlike this:\n\n```json\n{\n    \"schemaVersion\": 1,\n    \"routes\": {\n        \"foo\": {\n            \"get\": {\n                \"source\": \"./test/etc/fooGet.js\"\n            },\n            \"post\": {\n                \"source\": \"./test/etc/fooPost.js\"\n            },\n            \"put\": {\n                \"source\": \"./test/etc/fooPut.js\"\n            },\n            \"delete\": {\n                \"source\": \"./test/etc/fooDelete.js\"\n            },\n            \"head\": {\n                \"source\": \"./test/etc/fooHead.js\"\n            },\n            \"patch\": {\n                \"source\": \"./test/etc/fooPatch.js\"\n            },\n            \"options\": {\n                \"source\": \"./test/etc/fooOptions.js\"\n            }\n        },\n        \"bar\": {\n            \"get\": {\n                \"source\": \"./test/etc/barGet.js\"\n            },\n            \"post\": {\n                \"source\": \"./test/etc/barPost.js\"\n            }\n        }\n    }\n}\n```\nThis declares the route name, http method, and handler file on disk. this\nmodule will install these routes onto a restify server for you. The\ncorresponding handler file would look like:\n\n```javascript\nmodule.exports = function handler(req, res, next) {\n    res.send(200, 'Hello World');\n    next()\n};\n```\n\n## API\nSynopsis: `install(opts, cb)`\n\nInstalls routes as defined in opts into a restify server, invokes the callback\nwhen done.\n* `opts`: The options object containing\n    * `opts.server` The restify server to install the routes on to.\n    * `[opts.config]` The POJO of the enroute config.\n    * `[opts.basePath]` Used with `[opts.config]`. The POJO requires a\n    `basePath` to correctly resolve the route source file(s).\n    * `[opts.configPath]` The path to the enroute config on disk.\n    * `[opts.hotReload]` Indicate whether you want the server to reload the\n                         route from disk each time a request is served,\n                         defaults to false\n    * `[opts.excludePath]` The relative path to the basepath to exclude\n                           reloaded routes\n* `cb` The callback. Returns `Error` if there's an error installing the routes.\n\nNote only one of `opts.config` or `opts.configPath` is needed. The module will\neither read in the file from disk, or use a pre-populated POJO.\n\n`opts.hotReload` allows the restify server to reload the route from disk each\ntime the request is processed. This is extremely slow and should only be used\nin non-production instances.\n\n### Example\n```javascript\nconst enroute = require('restify-enroute');\nconst restify = require('restify');\n\nconst CONFIG = {\n    schemaVersion: 1,\n    routes: {\n        foo: {\n            get: {\n                source: './test/etc/fooGet.js'\n            },\n            post: {\n                source: './test/etc/fooPost.js'\n            },\n            delete: {\n                source: './test/etc/fooDelete.js'\n            },\n            head: {\n                source: './test/etc/fooHead.js'\n            },\n        }\n    }\n};\n\nconst server = restify.createServer();\n// install routes with enroute\nenroute.install({\n    config: CONFIG,\n    server: server,\n    basePath: __dirname\n}, function (err) {\n    if (err) {\n        console.error('unable to install routes');\n    } else {\n        console.log('routes installed');\n        SERVER.listen(1337);\n    }\n});\n```\n\nSynopsis: `validate(opts, cb)`\n\nParse and validate a enroute config. This will verify that the config\nis valid and return a POJO with the properties. Note only one of opts.config\nor opts.configPath is needed.\n\n* `opts` The options object containing\n    * `[opts.config]` The POJO of the config you want to validate.\n    * `[opts.configPath]` The path to the config on disk to validate.\n* `cb` The callback f(err, validatedConfig). Returns `Error` if there's an\n* error parsing or validating the config\n\n### Example\n```javascript\nconst enroute = require('restify-enroute');\n\nconst CONFIG = {\n    schemaVersion: 1,\n    routes: {\n        foo: {\n            get: {\n                source: './test/etc/fooGet.js'\n            },\n            post: {\n                source: './test/etc/fooPost.js'\n            },\n            delete: {\n                source: './test/etc/fooDelete.js'\n            },\n            head: {\n                source: './test/etc/fooHead.js'\n            },\n        }\n    }\n};\n\nconst server = restify.createServer();\n// install routes with enroute\nenroute.validate({\n    config: CONFIG,\n    basePath: __dirname\n}, function (err) {\n    if (err) {\n        console.error('unable to install routes');\n    } else {\n        console.log('config successfully validated');\n    }\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frestify%2Fenroute","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frestify%2Fenroute","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frestify%2Fenroute/lists"}