inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

탄탄한 백엔드 NestJS, 기초부터 심화까지

NestJS와 fastify & 협업을 위한 API 문서 만들기, CORS 문제

swagger 404

578

bee

작성한 질문수 10

1

안녕하세요.

고정 아이피에서 swagger가 404 에러가 나면서 들어가지지 않습니다. 원래 localhost docs로 잘 연결해서 사용했었는데 오늘 aws까지 연결 다 한 후 고정 아이피/docs로 swagger를 들어가보려고 보니까 에러가 나네요 ㅠㅠ 포트번호 80으로 들어가면 접속되는데, 원래 고정 아이피로는 docs 입장이 불가능 한가요? 

nest 버전은 8.0.0 swagger 버전은 5.1.5입니다

docs로 접속하면 아래의 오류가 뜹니다.

{
    "success": false,
    "timestamp": "2022-01-20T07:32:49.291Z",
    "statusCode": 404,
    "message": "Cannot GET /docs",
    "error": "Not Found"
}

main.ts의 코드입니다. 

  const config = new DocumentBuilder()
    .setTitle('C.I.C')
    .setDescription('blog project')
    .setVersion('1.0.0')
    .build();
  const document: OpenAPIObject = SwaggerModule.createDocument(app, config);
  SwaggerModule.setup('docs', app, document);

nodejs mongodb express ssr NestJS

답변 1

1

윤상석

안녕하세요!

고정아이피든 상관없이 잘 되어야 하는 것이 정상입니다!

해당 main.ts 파일 전체를 보여주실 수 있나요?? 도움 드리겠습니다!

0

bee

import { SuccessInterceptor } from './common/interceptors/success.interceptor';
import { HttpExceptionFilter } from './common/exceptions/http-excepton.filter';
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { ValidationPipe } from '@nestjs/common';
import { DocumentBuilder, OpenAPIObject, SwaggerModule } from '@nestjs/swagger';
import * as expressBasicAuth from 'express-basic-auth';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  app.useGlobalFilters(new HttpExceptionFilter());
  app.useGlobalInterceptors(new SuccessInterceptor());
  app.use(
    ['/docs', '/docs-json'],
    expressBasicAuth({
      challenge: true,
      users: {
        [process.env.SWAGGER_USER]: process.env.SWAGGER_PASSWORD,
      },
    }),
  );
  app.enableCors({
    origin: true,
    credentials: true,
  });
  const config = new DocumentBuilder()
    .setTitle('C.I.C')
    .setDescription('blog project')
    .setVersion('1.0.0')
    .build();
  const document: OpenAPIObject = SwaggerModule.createDocument(app, config);
  SwaggerModule.setup('docs', app, document);
  app.useGlobalPipes(
    new ValidationPipe({
      whitelist: true,
      forbidNonWhitelisted: true,
      transform: true,
    }),
  );
  app.enableCors({
    origin: true,
    credentials: true,
  });
  await app.listen(process.env.PORT_NO);
}
bootstrap();

main.ts 전체 입니다 감사합니다!!

프로젝트 환경 세팅할 때 최신 노드 버젼을 사용하시는 분들은 참고하셔도 좋을 것 같아요~

2

101

1

DTO에 대한 질문

1

97

2

백엔드 MVC에서 View의 역할은 무엇인가요?

1

111

2

추가 업데이트 관련 건

0

105

2

nest js 버전문제

0

95

2

mongdb 스키마 공식 문서와 형태가 다른 이유 궁금합니다.

0

112

1

라인 끝에 에러 표시(eslint) 때문에 구글 찾아 보니.

0

83

1

전체 고양이 조회 라우터 중 error.message 오류

0

82

1

캡슐화 추가 설명 중 단일책임원칙 관련 질문

0

115

0

42강 고양이끼리 소통 댓글 구현 중 Schema hasn't been registered for model 'comments' 에러 해결

0

86

1

채팅 이슈

0

137

1

모듈이 더 이상 지원하지 않는답니다

0

215

1

오류가 있습니다

0

114

1

import 에서 오류가 납니다

0

131

1

이런 오류가 나옵니다

0

106

1

에러가 발생합니다

0

117

1

프론트 에러 뜨는데 수정 안해주시나요

0

166

1

emit() broadcast.emit() 질문있습니다

0

107

1

서버연결이 안됩니다.

1

408

1

[PM2][ERROR] Command not found

0

528

1

S3에 업로드까지는 성공했는데 사진이 나오지 않습니다.

0

254

1

error_code : Property 'user' does not exist on type 'Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>'.ts(2339)

0

607

1

jwt를 따로 연습하고 있는데 env를 못읽는 것 같습니다.

0

330

2

Ec2로 안하시는 이유가 있을까요?

0

345

1