본문 바로가기

개발새발 개발자/JavaScript

(6)
[NestJS] DI 처리 후 Module에 등록하기 NestJS의 DI 방법은 스프링과 비슷하면서도 사뭇 다르다. 자바스크립트의 module 개념도 친숙하지 않은 상황에서 DI를 적용시키다 많이 헤맸다. 그동안 이리저리 부딪히면서 깨달은 내용을 정리해본다. 1. DI 처리하기 constructor(private readonly catsService: CatsService) {} 이렇게 constructor에서 해당 데이터, 그러니까 여기선 CatsService의 인스턴스를 생성하고 리턴하면 NestJS가 알아서 resolve 해준다. 앞에서 말했듯 NestJS는 스프링처럼 annotation을 이용해 DI를 한다. [auth.service.ts] @Injectable() export class AuthService { constructor( @Inject..
[NestJS] Promise 여부에 따른 test code에서의 throw 처리 방법 테스트 코드에서 toThrow를 통과하지 못하는 에러가 발생했다. 코드 내용은 아래와 같다. [auth.service.ts] createToken(address: string): Token { if (address === undefined) { throw new Error('address should be defined.'); } return { expiresIn: 3600, accessToken: this.jwtService.sign(address), }; } [auth.service.spec.ts] it('should throw "address should be defined"', async () => { service = new AuthService(instance(mockJwtService), i..
[NestJs] Authentication 도전기 - 2 (feat.초보에겐 너무나 어려운 공식 문서) 저번 글에 이어 이번엔 JWT를 적용한 Auth 예제를 따라해보았다. https://docs.nestjs.com/techniques/authentication#jwt-strategy Documentation | NestJS - A progressive Node.js web framework Nest is a framework for building efficient, scalable Node.js server-side applications. It uses progressive JavaScript, is built with TypeScript and combines elements of OOP (Object Oriented Progamming), FP (Functional Programming), and..
[NestJs] Authentication 도전기 - 1 (feat.초보에겐 너무나 어려운 공식 문서) 프로젝트로 Nest.JS를 사용하게 되었다. Node.JS로 서버 구축 시 사용하는 프레임워크인 것 같은데, 타입 스크립트를 지원한다. 나는 타입 스크립트는 커녕 자바 스크립트도 1도 모르고 주먹구구 식으로 개미 눈꼽만큼만 써봤었기에 헤매는 일이 많았다. 일단 Nest의 공식 홈페이지 문서를 참고해 JWT를 구현하라는 미션을 받았다. JWT가 뭔지도 이번에 처음 안 나새끼...리스펙.... JWT를 알고 싶다면 아래의 링크로! https://velopert.com/2389 [JWT] JSON Web Token 소개 및 구조 | VELOPERT.LOG 지난 포스트에서는 토큰 기반 인증 시스템의 기본적인 개념에 대하여 알아보았습니다. 이 포스트를 읽기 전에, 토큰 기반 인증 시스템에 대해서 잘 모르시는 분들..
[javascript] 스토리지 및 DOM 조작법 function setStyles() { var currentColor = localStorage.getItem('bgcolor'); var currentFont = localStorage.getItem('font'); var currentImage = localStorage.getItem('image'); document.getElementById('bgcolor').value = currentColor; document.getElementById('font').value = currentFont; document.getElementById('image').value = currentImage; htmlElem.style.backgroundColor = '#' + currentColor; pElem.s..
[Vue.js] router 정보 보기 this.$route