All Projects → eggjs → Egg Router Plus

eggjs / Egg Router Plus

Licence: mit
The missing router feature for eggjs

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Egg Router Plus

egg-sentry
Sentry Plugin For Egg.js
Stars: ✭ 18 (-84.62%)
Mutual labels:  egg, egg-plugin, eggjs
Egg 24time
A Twitter-like news and social server for Egg. 微信小程序社区全栈解决方案
Stars: ✭ 493 (+321.37%)
Mutual labels:  egg, eggjs, egg-plugin
Egg Authz
egg-authz is an authorization middleware for Egg.js based on Casbin
Stars: ✭ 50 (-57.26%)
Mutual labels:  egg, eggjs, egg-plugin
Egg Graphql
Stars: ✭ 345 (+194.87%)
Mutual labels:  egg, eggjs, egg-plugin
Cool Admin Api
cool-admin-api 是基于egg.js、typeorm、jwt等封装的api开发脚手架、快速开发api接口
Stars: ✭ 188 (+60.68%)
Mutual labels:  egg, eggjs, egg-plugin
Egg Oauth2 Server
🌟 OAuth2 server plugin for egg.js based on node-oauth2-server
Stars: ✭ 174 (+48.72%)
Mutual labels:  egg, eggjs, egg-plugin
Egg Cancan
cancancan like authorization plugin for Egg.js
Stars: ✭ 47 (-59.83%)
Mutual labels:  egg, eggjs, egg-plugin
egg-rbac
Role Based Access Control for eggjs
Stars: ✭ 32 (-72.65%)
Mutual labels:  egg, egg-plugin, eggjs
egg-parameters
Merge all parameters (ctx.params, ctx.request.query, ctx.request.body) into ctx.params like Rails application.
Stars: ✭ 24 (-79.49%)
Mutual labels:  egg, egg-plugin, eggjs
Egg View Ejs
egg view plugin for ejs.
Stars: ✭ 54 (-53.85%)
Mutual labels:  egg, egg-plugin
Egg Passport
passport plugin for egg
Stars: ✭ 98 (-16.24%)
Mutual labels:  egg, egg-plugin
Egg Schedule
Schedule plugin for egg
Stars: ✭ 76 (-35.04%)
Mutual labels:  egg, egg-plugin
Egg Mongoose
Stars: ✭ 386 (+229.91%)
Mutual labels:  egg, egg-plugin
Eggjs Note
《Egg.js 深入浅出学习笔记》(暂时停更)
Stars: ✭ 502 (+329.06%)
Mutual labels:  egg, eggjs
Egg Sofa Rpc
SOFARPC plugin for egg
Stars: ✭ 71 (-39.32%)
Mutual labels:  eggjs, egg-plugin
Egg Mongo Native
MongoDB egg.js plugin using native driver.
Stars: ✭ 69 (-41.03%)
Mutual labels:  eggjs, egg-plugin
Egg
🥚 Born to build better enterprise frameworks and apps with Node.js & Koa
Stars: ✭ 17,616 (+14956.41%)
Mutual labels:  egg, eggjs
Egg Valid
👮Validation plugin for eggjs
Stars: ✭ 10 (-91.45%)
Mutual labels:  egg, egg-plugin
Egg Sequelize
Sequelize for Egg.js
Stars: ✭ 540 (+361.54%)
Mutual labels:  egg, egg-plugin
Nideadmin
【未完成】NideAdmin - 基于 Vue.js + Egg.js 的微信小程序后台框架
Stars: ✭ 35 (-70.09%)
Mutual labels:  egg, eggjs

egg-router-plus

NPM version build status Test coverage David deps Known Vulnerabilities npm download

The missing router features for eggjs

Install

$ npm i egg-router-plus --save

Then mount plugin:

// {app_root}/config/plugin.js
exports.routerPlus = {
  enable: true,
  package: 'egg-router-plus',
};

Features

load app/router/**/*.js

this plugin will auto load router define at app/router/**/*.js.

Notice: all sub routers will be loaded before app/router.js, please ensure all the sub router definitions are not conflict(better to use app.router.namespace to create different namespaces for each sub router file).

app.router.namespace

app.router.namespace(prefix, ...middlewares);
  • prefix - {String}, the prefix string of sub router
  • middlewares - {...Function}, optional group middlewares

Support same as Router:

  • router.verb('path-match', app.controller.action);
  • router.verb('path-match', middleware1, ..., middlewareN, app.controller.action);
  • router.verb('router-name', 'path-match', app.controller.action);
  • router.verb('router-name', 'path-match', middleware1, ..., middlewareN, app.controller.action);

Note: prefix and path are not allow to be regex, and prefix can't be '/'.

// {app_root}/app/router.js
module.exports = app => {
  const subRouter = app.router.namespace('/sub');
  // curl localhost:7001/sub/test
  subRouter.get('/test', app.controller.sub.test);
  subRouter.get('sub_upload', '/upload', app.controller.sub.upload);

  // const subRouter = app.router.namespace('/sub/:id');
  // const subRouter = app.router.namespace('/sub', app.middleware.jsonp());

  // output: /sub/upload
  console.log(app.url('sub_upload'));
};

Known issues

  • sub redirect is not support, use app.router.redirect() or redirect to a named router.
const subRouter = app.router.namespace('/sub');

// will redirect `/sub/go` to `/anyway`, not `/sub/anyway`
subRouter.redirect('/go', '/anyway');

// just use router
router.redirect('/sub/go', '/sub/anyway');

// or redirect to a named router
subRouter.get('name_router', '/anyway', app.controller.sub.anyway);
// will redirect `/sub/go_name` to `/sub/anyway` which is named `name_router`
subRouter.redirect('/sub/go_name', 'name_router');

Questions & Suggestions

Please open an issue here.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].