Guards

Guards

마이크둜 μ„œλΉ„μŠ€ κ°€λ“œμ™€ 일반 κ°€λ“œ μ‚¬μ΄μ—λŠ” 차이가 μ—†μŠ΅λ‹ˆλ‹€. μ•Œμ•„μ•Όν•  μœ μΌν•œ 것은 HttpException을 λ°œμƒμ‹œν‚€λŠ” λŒ€μ‹  RpcException을 μ‚¬μš©ν•΄μ•Όν•œλ‹€λŠ” κ²ƒμž…λ‹ˆλ‹€.

info 힌트 RpcException ν΄λž˜μŠ€λŠ”@nestjs/microservices νŒ¨ν‚€μ§€μ—μ„œ λ…ΈμΆœλ©λ‹ˆλ‹€.

Binding guards

λ‹€μŒμ€ method-scoped guardλ₯Ό μ‚¬μš©ν•˜λŠ” μ˜ˆμ œμž…λ‹ˆλ‹€ (class-scoped도 μž‘λ™ν•©λ‹ˆλ‹€).

@@filename()
@UseGuards(AuthGuard)
@MessagePattern({ cmd: 'sum' })
accumulate(data: number[]): number {
  return (data || []).reduce((a, b) => a + b);
}

Last updated