Backend/Nest.js
-
[Nest.js] GuardsBackend/Nest.js 2024. 4. 4. 23:49
Guards 애플리케이션의 최전선에서 말그대로 애플리케이션을 보호하는 역할을 담당합니다. 가드를 이용하면 컨트롤러가 요청을 처리하기 전에 안전하지 않은 요청을 효과적으로 차단할 수 있습니다. 따라서 애플리케이션 보안을 위해서 필수적인 사용자 인증이나 접근 제어를 구현하는 데에 유용합니다. NestJS로 들어오는 요청은 컨트롤러(controller) 단에 도달하기 전에 반드시 가드를 거쳐가도록 되어 있습니다. 기본적으로, Guard는 @Injectable() 데코레이터로 주석이 달린 클래스로, CanActivate 인터페이스를 구현합니다. 단일 책임이 존재하고, 특정조건에 따라 요청을 라우터 핸들러에 의해 처리할지 여부 결정합니다. ⇒ 승인(Authorization) 특정 조건 : 권한, 역할, ACL(A..
-
[Nest.js] Test CodeBackend/Nest.js 2023. 11. 25. 18:36
Test Code를 작성해야 하는 이유 개발 과정 중 예상치 못한 문제를 미리 발견할 수 있는데, 에러를 클라이언트보다 빨리 발견할 수 있습니다. 작성한 코드가 의도한 대로 작동하는지 검증할 수 있습니다. 테스트 코드를 통해 동작하는 방식과 결과 확인이 가능합니다. 코드 수정이 필요한 상황에서 유연하고 안정적인 대응할 할 수 있게 해줍니다. 즉, 테스트 코드는 코드 변경에 대한 사이드 이펙트를 줄이는 예방책이 됩니다. 또한 코드 변경 시, 변경 부분으로 인한 영향도를 쉽게 파악할 수 있습니다. 리팩토링 시 기능 구현이 동일하게 되었다는 판단을 내릴 수 있습니다.리팩토링은 기존에 잘 동작하는 코드를 변경하여 발전시키는 작업인데, 리팩토링으로 인하여 기존 기능이 동작하지 않으면 굉장한 손해라고 볼 수 있습니..
-
[Nest.js] TypeORM, Repository PatternBackend/Nest.js 2023. 10. 2. 18:59
TypeORM Type ORM은 TypeScript를 기반으로 한 ORM(Object-Relational Mapping) 라이브러리로, 데이터베이스와의 상호작용을 추상화하여 개발자가 SQL 쿼리 대신 객체 지향적인 방식으로 데이터베이스를 다룰 수 있도록 도와줍니다. 즉, Typescript를 사용해 DB에 접근하고, DB를 다룰 수 있게 합니다. ORM(Object Relational Mapping) : ORM은 객체와 관계형 DB의 데이터를 자동으로 변형 및 연결하는 작업을 담당합니다. ORM을 이용하게 되면 객체와 DB의 변형을 유연하게 다룰 수 있습니다. TypeORM 주요 기능 1. Entity, Repository TypeORM은 엔티티 클래스를 통해 데이터베이스 테이블과의 매핑을 정의합니다. ..
-
Nest.jsBackend/Nest.js 2023. 9. 18. 22:59
Nest.js는 효율적이고 확장 가능한 서버 사이드 애플리케이션을 구축하기 위한 고성능의 Node.js 프레임워크입니다. 기업 친화적인 프레임워크이고, express보다 우리가 선호하는 구조를 적용할 수 있습니다. Typescript를 기반으로 하지만, Javascript로도 사용이 가능하며 OOP(Object Oriented Programming) FP(Functional Programming) FRP(Functional Reactive Programming) 와 같은 다양한 개발 방법론을 사용할 수 있습니다. 1. OOP (객체 지향 프로그래밍, Object-Oriented Programming) 객체 지향 프로그래밍은 컴퓨터 프로그래밍 패러다임 중 하나로, 프로그램을 객체들의 집합으로 보고 이들이 ..