
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
astroboy-router
Advanced tools
配合 astroboy 框架使用,查看更多:Astroboy
Authorize
不支持重配置路由级别错误的问题CustomRoute
不支持重置空 section
的问题CustomRoute
的 tpl
参数类型,支持定制额外的 sections
yarn add astroboy-router --save
# or
npm install astroboy-router --save
services/demo/BusinessService.ts
import { BaseClass } from "astroboy";
class BusinessService extends BaseClass {
queryParams(query: any) {
return { ...query };
}
queryParams2(query: any) {
return { ...query };
}
changeData(postData: any) {
return { ...postData };
}
changeData2(postData: any, query: any) {
return {
postData,
query
};
}
testB(post: any, query: any) {
return {
post,
query
};
}
}
export = BusinessService;
controllers/demo/DemoController.ts
// 导入astroboy框架,如果必要
// 导入所需的业务逻辑
// 导入astroboy-router
import { Controller } from "astroboy";
import BusinessService from "../services/demo/BusinessService";
import AnotherService from "...xxxx";
import ThirdService from "....xxxxxxxx";
import { Router, Service, Index, API, Metadata, RouteMethod, Inject } from "astroboy-router";
// 1.设置router前缀【必要】
// 2.继承astroboy基础控制器【必要】
// 3.支持使用Router装饰器做更多的事 1.0.0-rc.22
// @Router({
// prefix: "demo",
// auth: {
// rules: xxxx,
// metadata: xxxxx
// }
// })
@Router("demo")
class DemoController extends Controller {
// 服务级别DI @1.0.0-rc.17
// 服务需要继承astroboy基础类,并会在第一次访问是动态初始化
// 务必仅在typescript环境下使用, 确保emitDecoratorMetadata选项被打开
// !!注意字段不要使用business名称
@Inject() private readonly service03!: ThirdService;
// index页面,支持多路由
// index页面逻辑请自己实现
@Index(["index", "", "*"])
public async getIndexHtml() {
this.ctx.render("index.html");
}
// api定义
// 支持按照astroboy的规则,默认路由方法实现
// 限制:请确保business存在与路由方法同名的函数,此函数将被用于自动生成代码
@API("GET", "query")
@Service(BusinessService)
public queryParams!: RouteMethod;
@API("GET", "query2")
@Metadata("路由名字")
public queryParams02!: RouteMethod;
// 或者你可以自己实现路由方法
@API("POST", "change")
public async changeData() {
const postData = this.ctx.body;
const result = await this.business.changeData(postData);
this.ctx.json(0, "success", result);
}
// 支持获取body和query @1.0.0-rc.15
@API("POST", "change2")
public changeData2!: RouteMethod;
@API("POST", "change2")
@Service(AnotherService)
public changeData3!: RouteMethod;
}
router/demo.ts
import DEMO from "../controllers/demo/DemoController";
import { createRouter } from "astroboy-router";
export = createRouter(DEMO, "demo.DemoController", "/section01/section02");
[
'GET',
[
'/section01/section02/demo/index',
'/section01/section02/demo',
'/section01/section02/demo/*'
],
'demo.DemoController',
'getIndexHtml'
],
[
'GET',
'/section01/section02/api/demo/query',
'demo.DemoController',
'queryParams'
],
[
'路由名字',
'GET',
'/section01/section02/api/demo/query2',
'demo.DemoController',
'queryParams02'
]
[
'POST',
'/section01/section02/api/demo/change',
'demo.DemoController',
'changeData'
],
[
'POST',
'/section01/section02/api/demo/change2',
'demo.DemoController',
'changeData2'
]
```changeData2'
]
npm:^1.0.0-rc.16
支持路由(Router/Route)级别集成权限处理
services/demo/auth.ts
import { BaseClass } from "astroboy";
class AuthService extends BaseClass {
sleep(time = 500) {
return new Promise(resolve => setTimeout(resolve, time));
}
async checkIsLogin() {
await this.sleep(10);
return true;
}
async checkIsAdmin() {
await this.sleep(10);
if (this.ctx.header["auth"] === "admin") return true;
return false;
}
async checkIsSuperAdmin() {
await this.sleep(10);
if (this.ctx.header["auth"] === "s_a") return true;
return false;
}
}
export = AuthService;
import { AuthGuard } from "astroboy-router";
const authFac: (auth?: "admin" | "s_a") => AuthGuard = auth => {
return async (ctx: AstroboyContext) => {
if (auth === "admin") return await new AuthService(ctx).checkIsAdmin();
else if (auth === "s_a") return await new AuthService(ctx).checkIsSuperAdmin();
else return await new AuthService(ctx).checkIsLogin();
};
};
const admin = [authFac("admin")];
const s_a = [authFac("s_a")];
const ad_sa = [...admin, ...s_a];
const meta = { error: new Error("鉴权失败") };
@Router("demo")
@Service(DemoService)
@Authorize(ad_sa, meta)
// 支持Router级别挂载(可选),默认会作用到所有子路由逻辑之前触发
// 可以在单条路有上关闭,实现独立逻辑
// 鉴权失败会抛出异常,请使用全局异常处理
class DemoController extends BaseClass {
private business!: DemoService;
@Index(["", "*"])
public async getIndexHtml() {
this.ctx.render("demo/index.html");
}
@API("GET", "testA")
// 继承Router级别鉴权,并不新增额外的鉴权
public testA!: RouteMethod;
@API("POST", "testB")
@Authorize(admin, scope_meta)
// 不继承Router鉴权逻辑,独立定义当前Route的权限处理
public testB!: RouteMethod;
@API("GET", "testC")
@NoAuthorize()
// 单独Route清空鉴权逻辑
// 如果没有定义Router级别鉴权,就不需要这样处理
public testC!: RouteMethod;
}
FAQs
A router plugin for astroboy.ts.
The npm package astroboy-router receives a total of 2 weekly downloads. As such, astroboy-router popularity was classified as not popular.
We found that astroboy-router demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.