相关疑难解决方法(0)

从快速中间件中排除路由

我有一个节点应用程序像其他微服务前面的防火墙/调度程序一样坐着,它使用如下的中间件链:

...
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设置过滤器:除了/:仅?

javascript middleware node.js coffeescript express

22
推荐指数
3
解决办法
3万
查看次数

在 Guard 中访问请求的原始正文?

有没有办法访问请求的原始正文?不是已经解析成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

9
推荐指数
2
解决办法
5649
查看次数

如何使用NestJS将纯文本作为请求正文传递?

NestJS应用程序中的一种控制器方法应该以纯文本为主体,但是每当我尝试发出请求时,该参数都会作为一个空对象接收。这是否有可能,或者我将不得不创建某种DTO来传递单个字符串?

例:

@Post()
  myFunction(@Body() id: string) {
    // do something here
  }
Run Code Online (Sandbox Code Playgroud)

javascript http typescript postman nestjs

3
推荐指数
2
解决办法
1594
查看次数