본문 바로가기
반응형

Back-End/NestJs3

[NestJS] must be a number conforming to the specified constraints - body dto 타입 에러 해결 [ 문제점 ] Nest Js에서 post나 put을 할 때 body에 데이터를 담아서 보낸다. 이때 dto로 검증을 하는데 id는 number을 받기 위해서 다음과 같은 dto를 만들었다. import { IsNumber, IsOptional, IsString } from 'class-validator'; export class UpdatePlanDto { @IsNumber() readonly id: number; @IsOptional() @IsString() readonly date: string; } 이렇게 만들고 요청을 보내니 다음과 같은 400오류가 뜨면서 작동하지 않았다. [ 해결 방법 ] 이러한 오류가 나온 이유는 message에도 설명해주지만 id의 type이 number가 아니라는 것이다... 2022. 6. 11.
[NestJS] typeOrm migration 정리 typeorm 에서 database migration을 하기 위해서는 ormconfig에 마이그레이션 파일이 들어갈 위치를 지정해 주어야 합니다. root directory에 ormconfig.json파일에 써도 무방하지만 저는 develop 환경과 production 환경을 분리하기 위해서 ormconfig.ts파일을 만들고 환경변수 NODE_ENV에 따라서 두 환경을 분리하였습니다. import { ConnectionOptions } from 'typeorm'; const typeormConfig: ConnectionOptions = process.env.NODE_ENV ? { url: process.env.DATABASE_URL, type: 'postgres', synchronize: false, .. 2022. 6. 10.
[NestJS] Heroku, no pg_hba.conf entry for host, SSL off 해결하기 [문제점] TypeOrm과 Postgres를 사용해서 Nestjs db를 세팅하고 heroku에 배포하는 과정에서 문제가 발생했다. typeorm설정을 하고 배포를 하였더니 서버오류가 나서 heroku log를 살펴보았더니 다음과 같은 에러가 나왔다. ERROR [ExceptionHandler] no pg_hba.conf entry for host "", user "", database "", SSL off [해결 방법] postgres의 pg_hba.conf 파일에서 문제가 생긴 줄 알았으나 구글검색을 해보니 다른 원인을 알 수 있었다. typeorm에서 SSL설정을 해주면 문제는 해결된다. ormconfig.json에서 수정을 하거나 typeorm.forRoot 내부에서 바로 수정을 하면된다. 위의 .. 2022. 2. 12.
반응형