我有一个节点应用程序像其他微服务前面的防火墙/调度程序一样坐着,它使用如下的中间件链:
...
app.use app_lookup
app.use timestamp_validator
app.use request_body
app.use checksum_validator
app.use rateLimiter
app.use whitelist
app.use proxy
...
Run Code Online (Sandbox Code Playgroud)
但是对于特定的GET路由,我想跳过除rateLimiter和proxy之外的所有路由.他们是否可以使用Rails before_filter设置过滤器:除了/:仅?
有没有办法访问请求的原始正文?不是已经解析成json了吗?
@Injectable()
export class WooGuard implements CanActivate {
secret: string;
constructor(
private readonly reflector: Reflector,
private configService: ConfigService,
) {
this.secret = this.configService.get<string>("woocommerce.webhook.secret");
}
async canActivate(
context: ExecutionContext,
): Promise<boolean> {
const request = context.switchToHttp().getRequest<Request>();
request.body // this is parsed json
// I am calculating the sha256 hash of the body with a secret for a webhook.
// due to how the raw json is vs. the JSON.stringify(request.body), the signature is never the same.
}
}
Run Code Online (Sandbox Code Playgroud) NestJS应用程序中的一种控制器方法应该以纯文本为主体,但是每当我尝试发出请求时,该参数都会作为一个空对象接收。这是否有可能,或者我将不得不创建某种DTO来传递单个字符串?
例:
@Post()
myFunction(@Body() id: string) {
// do something here
}
Run Code Online (Sandbox Code Playgroud) javascript ×2
nestjs ×2
coffeescript ×1
express ×1
http ×1
middleware ×1
node.js ×1
postman ×1
typescript ×1