Gathering detailed insights and metrics for egg-router-decorator
Gathering detailed insights and metrics for egg-router-decorator
Gathering detailed insights and metrics for egg-router-decorator
Gathering detailed insights and metrics for egg-router-decorator
egg-decorator-router
Define egg.js router and middleware use decorator
egg-router-util
egg router decorator util -> simple way to define api router
egg-swagger-decorator
using decorator to make router definitions and automatically generate swagger doc for egg.js
egg-route-decorator
Define egg.js router and middleware use decorator
装饰者模式写egg-router(Routers for eggjs by decorator pattern)。
npm install egg-router-decorator
Typescript
Module System
Min. Node Version
Node Version
NPM Version
TypeScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
8 Stars
12 Commits
3 Forks
1 Watchers
1 Branches
1 Contributors
Updated on Aug 03, 2021
Latest Version
2.1.0
Package Id
egg-router-decorator@2.1.0
Unpacked Size
18.22 kB
Size
5.62 kB
File Count
7
NPM Version
6.3.0
Node Version
8.11.1
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
装饰者模式写egg-router(Routers for eggjs by decorator pattern)。
1npm install --save egg-router-decorator
In router.ts
or route.js
1// router.ts or route.js 2import { Application } from 'egg'; 3import { initRouter } from 'egg-router-decorator'; 4 5export default (app: Application) => { 6 initRouter(app); 7}
1// router.ts or `router.js` 2initRouter(app, { prefix: '/api' }) 3 4// controller.ts or `controller.js` 5export default class index extends Controller { 6 @routerDecorator.get('/user') //===>>/api/user 7 async get() { 8 this.ctx.body = 'hello, egg-router-decorator.' 9 } 10} 11
1// controller.ts or `controller.js` 2import routerDecorator from 'egg-router-decorator'; 3 4@routerDecorator.prefix('/home') 5export default class home extends Controller { 6 @routerDecorator.get('/test') //===>>/home/test 7 async get() { 8 this.ctx.body = 'hello, egg-router-decorator.' 9 } 10} 11
Router middleware will run before the target function.
Example
1import { Controller } from 'egg'; 2import routerDecorator from 'egg-router-decorator'; 3 4// @routerDecorator.prefix('/example') 5@routerDecorator.prefix('/example', (ctx, next) => { 6 console.log(ctx.request.URL); 7 console.log('ExampleController的prefix中的中间件1'); 8 next(); 9}, async (ctx, next) => { 10 await next(); 11 console.log(ctx.request.URL); 12 console.log('ExampleController的prefix中的中间件2'); 13}) 14export default class ExampleController extends Controller { 15 16 @routerDecorator.get('/index') // ===>>/example/index get 17 @routerDecorator.post('/index2') // ===>>/example/index2 post 18 public async test1 () { 19 const { ctx } = this; 20 ctx.body = 'hello, egg-router-decorator.' 21 } 22 23 @routerDecorator.put('/parms/:id') // ===>>/parms/:id put 24 public async test2 () { 25 const { ctx } = this; 26 ctx.body = 'hello, egg-router-decorator.' 27 } 28 29 @routerDecorator.del('/parms/:id/:pwd', isLogin, hasDelAuth) // ===>>/parms/:id/:pwd del 30 public async test3 () { 31 const { ctx } = this; 32 ctx.body = 'hello, egg-router-decorator.' 33 } 34} 35 36// isLogin middleware 37const isLogin = async (ctx, next) => { 38 if (ctx.params['id']) { 39 await next(); 40 } else { 41 ctx.status = 401; 42 } 43} 44 45// hasDelAuth middleware 46const hasDelAuth = async (ctx, next) => { 47 if (ctx.params['pwd'] === 'admin') { 48 await next(); 49 // ctx.body = 'xxx' 50 } else { 51 ctx.status = 403; 52 } 53} 54
The MIT License (MIT)
Copyright (c) hzsuqin 15957136119@163.com
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 0/12 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
76 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
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