Installations
npm install egg-router-plus
Developer Guide
Typescript
Yes
Module System
N/A
Min. Node Version
>=12
Node Version
10.16.0
NPM Version
6.14.8
Score
68.5
Supply Chain
96.4
Quality
81.1
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Developer
eggjs
Download Statistics
Total Downloads
336,119
Last Day
215
Last Week
1,573
Last Month
7,041
Last Year
86,068
GitHub Statistics
140 Stars
22 Commits
9 Forks
19 Watching
1 Branches
27 Contributors
Package Meta Information
Latest Version
2.0.0
Package Id
egg-router-plus@2.0.0
Size
5.00 kB
NPM Version
6.14.8
Node Version
10.16.0
Publised On
12 Jul 2021
Total Downloads
Cumulative downloads
Total Downloads
336,119
Last day
-13.7%
215
Compared to previous day
Last week
-5.3%
1,573
Compared to previous week
Last month
12%
7,041
Compared to previous month
Last year
27%
86,068
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
3
egg-router-plus
The missing router features for eggjs
Install
1$ npm i egg-router-plus --save
Then mount plugin:
1// {app_root}/config/plugin.js 2exports.routerPlus = { 3 enable: true, 4 package: 'egg-router-plus', 5};
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
1app.router.namespace(prefix, ...middlewares);
prefix
- {String}, the prefix string of sub routermiddlewares
- {...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);
prefix
and path
are not allow to be regex
, and prefix
can't be '/'.
1// {app_root}/app/router.js 2module.exports = app => { 3 const subRouter = app.router.namespace('/sub'); 4 // curl localhost:7001/sub/test 5 subRouter.get('/test', app.controller.sub.test); 6 subRouter.get('sub_upload', '/upload', app.controller.sub.upload); 7 8 // const subRouter = app.router.namespace('/sub/:id'); 9 // const subRouter = app.router.namespace('/sub', app.middleware.jsonp()); 10 11 // output: /sub/upload 12 console.log(app.url('sub_upload')); 13};
Every different prefix will bind to different router instance, and all the namespaces will sort by trie tree to ensure best match.
1module.exports = app => { 2 const apiRouter = app.router.namespace('/api'); 3 const apiWebRouter = app.router.namespace('/api/web'); 4 const apiWebAdminRouter = app.router.namespace('/api/web/admin'); 5 apiRouter.get('/:a/:b/:c', controller.api.one); 6 apiWebRouter.get('/:a/:b', controller.api.two); 7 apiWebAdminRouter.get('/:a', controller.api.three); 8 // /api/web/admin/hello => controller.api.three 9 // /api/web/foo/hello => controller.api.two 10 // /api/foo/bar/hello => controller.api.one 11};
Known issues
- sub
redirect
is not support, useapp.router.redirect()
or redirect to a named router.
1const subRouter = app.router.namespace('/sub'); 2 3// will redirect `/sub/go` to `/anyway`, not `/sub/anyway` 4subRouter.redirect('/go', '/anyway'); 5 6// just use router 7router.redirect('/sub/go', '/sub/anyway'); 8 9// or redirect to a named router 10subRouter.get('name_router', '/anyway', app.controller.sub.anyway); 11// will redirect `/sub/go_name` to `/sub/anyway` which is named `name_router` 12subRouter.redirect('/sub/go_name', 'name_router');
Questions & Suggestions
Please open an issue here.
License
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 10/22 approved changesets -- score normalized to 4
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/nodejs.yml:26: update your workflow using https://app.stepsecurity.io/secureworkflow/eggjs/egg-router-plus/nodejs.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/nodejs.yml:29: update your workflow using https://app.stepsecurity.io/secureworkflow/eggjs/egg-router-plus/nodejs.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/nodejs.yml:40: update your workflow using https://app.stepsecurity.io/secureworkflow/eggjs/egg-router-plus/nodejs.yml/master?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/nodejs.yml:35
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 third-party GitHubAction dependencies pinned
- Info: 1 out of 2 npmCommand dependencies pinned
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/nodejs.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 13 are checked with a SAST tool
Score
4.4
/10
Last Scanned on 2024-12-23
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More