: 컨트롤러
@Post('signup')
create(@Body() createUserDto: CreateUserDto) {
// 성공 여부를 최종적으로 response
return this.usersService.create(createUserDto);
}
: 프로바이더
create(createUserDto: CreateUserDto) {
const { id, password, nickname } = createUserDto;
// orm으로 실제 데이터 생성(있나 먼저 확인 후)
// 성공 여부에 따른 response
return `Id : ${id}, Pwd : ${password}, nickname : ${nickname}`;
}
그리고 실제로 프론트에서 이를 호출했다.
axiosFetch("http://api.localhost:4000/users/signup", "POST", {
id,
password,
nickname,
});
호출을 할 때는 axios 모듈을 사용했다. 로컬끼리의 통신이었지만, 일단 정상적으로 작동하고, 데이터를 주고 받을 수 있다.
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.enableCors({
origin: true, //여기에 url을 넣어도된다.
credentials: true,
});
await app.listen(4000);
}
bootstrap();
중간에 cors 관련 문제가 생겼었어서 일단은 전부다 풀어줬다. 그리고 백엔드를 4000포트로 로컬에서 돌려놨고, 프론트는 3000으로 돌려놨다. 이 다음 스텝으로 인증을 구현해놓고, 인증 내용을 바탕으로 로그인 이후의 처리 등을 다듬을 예정이다.