{"id":15834776,"url":"https://github.com/kaelzhang/roe-define-router","last_synced_at":"2026-05-03T02:42:10.704Z","repository":{"id":65491140,"uuid":"177255535","full_name":"kaelzhang/roe-define-router","owner":"kaelzhang","description":"Utility tool to help generate route definitions of roe or egg","archived":false,"fork":false,"pushed_at":"2019-07-02T02:46:07.000Z","size":15,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-25T13:16:19.169Z","etag":null,"topics":["egg","nodejs","roe"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kaelzhang.png","metadata":{"files":{"readme":"README.md","changelog":"HISTORY.md","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":"2019-03-23T06:57:11.000Z","updated_at":"2019-07-02T02:46:09.000Z","dependencies_parsed_at":"2023-01-25T18:45:28.482Z","dependency_job_id":null,"html_url":"https://github.com/kaelzhang/roe-define-router","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaelzhang%2Froe-define-router","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaelzhang%2Froe-define-router/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaelzhang%2Froe-define-router/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaelzhang%2Froe-define-router/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kaelzhang","download_url":"https://codeload.github.com/kaelzhang/roe-define-router/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246397402,"owners_count":20770548,"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":["egg","nodejs","roe"],"created_at":"2024-10-05T14:01:53.917Z","updated_at":"2026-05-03T02:42:05.684Z","avatar_url":"https://github.com/kaelzhang.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/kaelzhang/roe-define-router.svg?branch=master)](https://travis-ci.org/kaelzhang/roe-define-router)\n[![Coverage](https://codecov.io/gh/kaelzhang/roe-define-router/branch/master/graph/badge.svg)](https://codecov.io/gh/kaelzhang/roe-define-router)\n\u003c!-- optional appveyor tst\n[![Windows Build Status](https://ci.appveyor.com/api/projects/status/github/kaelzhang/roe-define-router?branch=master\u0026svg=true)](https://ci.appveyor.com/project/kaelzhang/roe-define-router)\n--\u003e\n\u003c!-- optional npm version\n[![NPM version](https://badge.fury.io/js/roe-define-router.svg)](http://badge.fury.io/js/roe-define-router)\n--\u003e\n\u003c!-- optional npm downloads\n[![npm module downloads per month](http://img.shields.io/npm/dm/roe-define-router.svg)](https://www.npmjs.org/package/roe-define-router)\n--\u003e\n\u003c!-- optional dependency status\n[![Dependency Status](https://david-dm.org/kaelzhang/roe-define-router.svg)](https://david-dm.org/kaelzhang/roe-define-router)\n--\u003e\n\n# roe-define-router\n\nThis package is an utility tool to help generate route definitions of [roe](https://github.com/kaelzhang/roe) or [egg](https://npmjs.org/package/egg)\n\n`roe-define-router` makes it quite easy to define\n\n- normal roe or egg routes\n- SSR pages routes (this features requires that `app.next` exists in which `app` is the instance of roe or egg, and `app.next` should be an instance of [`next server`](https://npmjs.org/package/next-server))\n- static files serving.\n\n## Install\n\n```sh\n$ npm i roe-define-router\n```\n\n## Usage\n\napp/router.js\n\n```js\nconst defineRouter = require('roe-define-router')\n\nconst routes = {\n  routes: {\n    '/say-hello': 'say.hello'\n  },\n\n  pages: {\n    '/:lang': 'index'\n  },\n\n  static: {\n    '/static': 'static'\n  }\n}\n\nconst config = {\n  static: {\n    root: '/path/to/project'\n  }\n}\n\nmodule.exports = defineRouter(routes, config, app =\u003e {\n  // manually set other route definitions\n})\n```\n\n## defineRouter(routes, config?, extra?)\n\n- **routes.routes?** **config?.routes?** routes and options of [`egg-define-router`](https://github.com/kaelzhang/egg-define-router)\n- **routes.pages?** **routes?.pages?** pages and config of [`egg-ssr-pages`](https://github.com/kaelzhang/egg-ssr-pages)\n- **routes.static?** **routes?.static?** files and options of [`egg-serve-static`](https://github.com/kaelzhang/egg-serve-static)\n- **extra?** `Function(app, apply?)` an extra router function\n  - **app** `RoeApplication | EggApplication` the server instance\n  - **apply?** `Function(app)` method to apply `roe-define-router` to the application.\n\nReturns a roe/egg router function which accepts app as the only one parameter.\n\n## About `extra`\n\nIf the `extra` function only contains one parameter, the `routes` will be applied to the application before invoking `extra`.\n\n```js\nmodule.exports = defineRouter(routes, config, app =\u003e {\n  // `routes` has already been applied\n})\n```\n\nIf the function contains two parameters, then the second argument `apply` is the function to apply the `routes`, so that we need to manually invoke `apply(app)` to apply the routes what `roe-define-router` defined.\n\n```js\nmodule.exports = defineRouter(routes, config, (app, apply) =\u003e {\n  // do something with `app.router`\n\n  // Don't forget this line below:\n  apply(app)\n\n  // do something with `app.router`\n})\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkaelzhang%2Froe-define-router","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkaelzhang%2Froe-define-router","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkaelzhang%2Froe-define-router/lists"}