
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
koa-router-class
Advanced tools
koa 路由,将路由转发到 class 方法上
基于 path-to-regexp 库
const { Router } = require('koa-router-class');
app.use(Router());
import Result from '../../src/core/Result';
import { Path, RequestMethod, BaseController, Param, Around, middlewareToAround, Inject } from '../../src/index';
import Test from '../service/Test';
// Path 修饰 class 时,参数为根路由(参数只能一个)
// Path 修饰 method 时,参数为方法路由(参数可有多个)
@Around(async (point) => {
console.log('----around before----')
const { proceed, args } = point;
const result = await proceed(args);
console.log('----around after----')
return result;
})
export default class Index extends BaseController {
@Inject(Test)
t: Test;
@Path('/')
index() {
console.log(this.t.test());
return this.send('This is index');
}
@Path({ value: '/post', method: RequestMethod.POST })
post() {
return this.send('This is post page.');
}
@Path('/test/:name')
@Around(middlewareToAround((ctx, next) => {
console.log('》》', ctx.request.path);
return next();
}))
test(@Param('name') name: string) {
console.log(`进入方法,参数:${JSON.stringify(name)}`)
return Result.send(`这里是测试页面,地址 ${this.req.path}`);
}
// 私有化方法,无路由不会进入此 action
hehe() {
return this.send('hehe');
}
}
FAQs
koa 路由,将路由转发到 class 方法上 基于 path-to-regexp 库
The npm package koa-router-class receives a total of 4 weekly downloads. As such, koa-router-class popularity was classified as not popular.
We found that koa-router-class demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 9 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.