Gathering detailed insights and metrics for egg-decorator-router
Gathering detailed insights and metrics for egg-decorator-router
Gathering detailed insights and metrics for egg-decorator-router
Gathering detailed insights and metrics for egg-decorator-router
egg-router-util
egg router decorator util -> simple way to define api router
egg-router-decorator
Routers for eggjs by decorator pattern.
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
a way, that create route、middleware and others use decorator mode
npm install egg-decorator-router
Typescript
Module System
Min. Node Version
Node Version
NPM Version
55
Supply Chain
88.1
Quality
70.9
Maintenance
25
Vulnerability
98.2
License
JavaScript (100%)
Total Downloads
14,197
Last Day
3
Last Week
24
Last Month
173
Last Year
3,505
MIT License
4 Stars
77 Commits
3 Forks
2 Watchers
17 Branches
3 Contributors
Updated on Apr 09, 2023
Minified
Minified + Gzipped
Latest Version
1.0.7
Package Id
egg-decorator-router@1.0.7
Unpacked Size
16.79 kB
Size
4.90 kB
File Count
11
NPM Version
6.14.8
Node Version
12.18.4
Cumulative downloads
Total Downloads
Last Day
-40%
3
Compared to previous day
Last Week
-36.8%
24
Compared to previous week
Last Month
-6.5%
173
Compared to previous month
Last Year
23.2%
3,505
Compared to previous year
4
Define egg.js router and middleware use decorator.
1npm i egg-decorator-router --save
1// {app_root}/config/plugin.js 2exports.decoratorRouter = { 3 enable: true, 4 package: 'egg-decorator-router' 5}
基于 typescript 的 eggjs 项目可直接使用装饰器
如果是 js 项目,则需要手动安装babel-plugin-transform-decorators-legacy
和babel-plugin-transform-object-rest-spread
这两个包,并在项目里加入.babelrc
文件
.babelrc 定义如下:
1{ 2 "plugins": ["transform-decorators-legacy", "transform-object-rest-spread"] 3}
The full path is combin between root-path and sub-path.
在 controller 中先引入依赖
1const { 2 Route, 3 HttpAll, 4 HttpGet, 5 HttpPost, 6 HttpPut, 7 HttpPatch, 8 HttpDelete, 9 Middleware 10} = require('egg-decorator-router')
如果使用 typescript
1import { 2 Route, 3 HttpAll, 4 HttpGet, 5 HttpPost, 6 HttpPut, 7 HttpPatch, 8 HttpDelete, 9 Middleware 10} from 'egg-decorator-router'
Define a root path on controller
1// root path is '/' 2@Route() 3 4// root path is '/' 5@Route('/') 6 7// root path is '/routename' 8@Route('/routename') 9 10// root path is '/routename/action' 11@Route('/routename/action')
Parameter is available
1@Route('/routename/:name')
HttpMethod include HttpGet
HttpPost
HttpPut
HttpPatch
HttpDelete
and HttpAll
Define a sub-path in controller's method
1// sub-path is '/' 2@HttpGet() 3 4// sub-path is '/' 5@HttpGet('/') 6 7// sub-path is '/action' 8@HttpGet('/action') 9 10// sub-path is '/action/:id' 11@HttpGet('/action/:id')
1@Middleware(routeM)
1'use strict' 2 3const { Controller } = require('egg') 4const { Route, HttpGet, Middleware, filters } = require('egg-decorator-router') 5const { DefaultFilter } = filters 6 7const routeM = (ctx, next) => { 8 console.log('passed route middleware') 9 next() 10} 11 12const actionM = i => { 13 return (ctx, next) => { 14 console.log('passed action middleware ' + i) 15 next() 16 } 17} 18 19@Route() 20@Middleware(routeM) 21class HomeController extends Controller { 22 @HttpGet('/') // path: / 23 async index() { 24 await new Promise(resolve => { 25 this.ctx.body = 'ssss' 26 resolve() 27 }) 28 } 29 30 @HttpGet() // path: /func1 31 @Middleware(actionM(2), 2) 32 @Middleware(actionM(1), 1) 33 func1(ctx) { 34 ctx.body = 'hi, func1' 35 } 36 37 @HttpGet(':id') // path: /:id 38 @DefaultFilter('aaa') 39 func2(ctx) { 40 ctx.body = 'hi, func2' + ctx.params.id 41 } 42} 43 44module.exports = HomeController
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 0/18 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 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
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
84 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-06-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