BE/NestJS
-
NestJS 공식문서: https://docs.nestjs.com/security/cors CORS는 서비스 하고 있지 않는 사이트에서 의도치 않는 접근을 막아주는 것이다. 프론트엔드에서 Api를 사용하려면 설정해주어야 한다. app.enableCors(); main.ts import { ValidationPipe } from '@nestjs/common'; import { NestFactory } from '@nestjs/core'; import { DocumentBuilder, OpenAPIObject, SwaggerModule } from '@nestjs/swagger'; import { AppModule } from './app.module'; import { HttpExceptionFilter ..
NestJS : CORSNestJS 공식문서: https://docs.nestjs.com/security/cors CORS는 서비스 하고 있지 않는 사이트에서 의도치 않는 접근을 막아주는 것이다. 프론트엔드에서 Api를 사용하려면 설정해주어야 한다. app.enableCors(); main.ts import { ValidationPipe } from '@nestjs/common'; import { NestFactory } from '@nestjs/core'; import { DocumentBuilder, OpenAPIObject, SwaggerModule } from '@nestjs/swagger'; import { AppModule } from './app.module'; import { HttpExceptionFilter ..
2022.06.03 -
NestJS 공식문서: https://docs.nestjs.com/openapi/introduction $ npm install --save @nestjs/swagger swagger-ui-express main.ts import { NestFactory } from '@nestjs/core'; import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger'; import { AppModule } from './app.module'; async function bootstrap() { const app = await NestFactory.create(AppModule); const config = new DocumentBuilder() .setTitle..
NestJS : swaggerNestJS 공식문서: https://docs.nestjs.com/openapi/introduction $ npm install --save @nestjs/swagger swagger-ui-express main.ts import { NestFactory } from '@nestjs/core'; import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger'; import { AppModule } from './app.module'; async function bootstrap() { const app = await NestFactory.create(AppModule); const config = new DocumentBuilder() .setTitle..
2022.06.02 -
NestJS 디자인 패턴 Controller express에서 router의 역할 request, resposne, domain, url 등을 제어 Service 실제 비즈니스 로직 DTO : Data Transfer Object → 계층간 데이터 교환을 위한 객체 DB에서 데이터를 얻어 Service나 Controller 등으로 보낼 때 사용하는 객체 Request와 Response용 DTO는 View를 위한 클래스 회원가입 Service cats.request.dto.ts 생성 import { IsEmail, IsNotEmpty, IsString } from 'class-validator'; export class CatRequestDto { @IsEmail() @IsNotEmpty() email: ..
NestJS : DTO 패턴 & 회원가입 serviceNestJS 디자인 패턴 Controller express에서 router의 역할 request, resposne, domain, url 등을 제어 Service 실제 비즈니스 로직 DTO : Data Transfer Object → 계층간 데이터 교환을 위한 객체 DB에서 데이터를 얻어 Service나 Controller 등으로 보낼 때 사용하는 객체 Request와 Response용 DTO는 View를 위한 클래스 회원가입 Service cats.request.dto.ts 생성 import { IsEmail, IsNotEmpty, IsString } from 'class-validator'; export class CatRequestDto { @IsEmail() @IsNotEmpty() email: ..
2022.05.29 -
Nest Js MongoDB Schema 공식 문서: https://docs.nestjs.com/techniques/mongodb DB Schema 설계 - cats.schema.ts import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; import { Document, SchemaOptions } from 'mongoose'; const options: SchemaOptions = { timestamps: true, }; @Schema(options) // schema 정의 export class Cat extend Document{ @Prop({ required: true, unique: true, }) email: string; @Prop..
NestJS : DB Schema 설계 및 ValidationNest Js MongoDB Schema 공식 문서: https://docs.nestjs.com/techniques/mongodb DB Schema 설계 - cats.schema.ts import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; import { Document, SchemaOptions } from 'mongoose'; const options: SchemaOptions = { timestamps: true, }; @Schema(options) // schema 정의 export class Cat extend Document{ @Prop({ required: true, unique: true, }) email: string; @Prop..
2022.05.28 -
NestJS 공식문서: https://docs.nestjs.com/first-steps NestJS 프로젝트 생성 nestnewproject−nameMongodependency설치 npm install --save @nestjs/mongoose mongoose app.module.ts 파일에 mongoose module을 import import { Module } from '@nestjs/common'; import { MongooseModule } from '@nestjs/mongoose'; @Module({ imports: [MongooseModule.forRoot('mongodb://localhost/nest')], }) export class AppModule {} 모듈들이 여러..
NestJS : MongoDB 연결 및 환경 변수 설정NestJS 공식문서: https://docs.nestjs.com/first-steps NestJS 프로젝트 생성 nestnewproject−nameMongodependency설치 npm install --save @nestjs/mongoose mongoose app.module.ts 파일에 mongoose module을 import import { Module } from '@nestjs/common'; import { MongooseModule } from '@nestjs/mongoose'; @Module({ imports: [MongooseModule.forRoot('mongodb://localhost/nest')], }) export class AppModule {} 모듈들이 여러..
2022.05.28 -
0. 요청 1. middleware (미들웨어) 2. guards (가드) - 주로 permission (인증) 처리를 할 때 사용합니다. 3. pre-interceptors (인터셉터) - 주로 post-interceptor를 위한 변수 선언, 함수 실행을 합니다. (선택) 4. Pipes (파이프) - 변환(요청 바디를 원하는 형식으로 변환), 유효성 검사를 합니다. 5. Controller (컨트롤러) - 라우터 역할을 수행합니다. (서비스 로직의 결과를 응답합니다.) 6. Service (서비스 ; 컨트롤러 안에 정의되어 있다면) - 해당 요청에 대한 핵심 로직이 수행됩니다. 7. post-interceptor (인터셉터) - 주로 pre-interceptor 로직을 가지고 응답한 데이터를 가공하..
NestJS : 로직0. 요청 1. middleware (미들웨어) 2. guards (가드) - 주로 permission (인증) 처리를 할 때 사용합니다. 3. pre-interceptors (인터셉터) - 주로 post-interceptor를 위한 변수 선언, 함수 실행을 합니다. (선택) 4. Pipes (파이프) - 변환(요청 바디를 원하는 형식으로 변환), 유효성 검사를 합니다. 5. Controller (컨트롤러) - 라우터 역할을 수행합니다. (서비스 로직의 결과를 응답합니다.) 6. Service (서비스 ; 컨트롤러 안에 정의되어 있다면) - 해당 요청에 대한 핵심 로직이 수행됩니다. 7. post-interceptor (인터셉터) - 주로 pre-interceptor 로직을 가지고 응답한 데이터를 가공하..
2022.05.28