Backend/Nestjs

[NestJS] Docker 304 undefined 에러

ASHE SUN 2022. 2. 14. 18:40
반응형

문제

API 배포 후 개발 서버에서 도커 로그 파일 확인 결과 304 undefined 이슈 발생

 
도커 로그 파일 확인 코드

docker logs -f [컨테이너 ID]

 

원인

chrome에서 동적 메소드 실행 시 캐시가 저장되기 때문에 발생한 이슈
 
 

해결

main.ts 코드 수정

// main.ts

const app = await NestFactory.create<NestExpressApplication>(AppModule);
// 동적 요청에 대한 응답을 보낼 때 etag 생성을 하지 않도록 설정 (모든 캐시 저장 X)
app.set('etag', false);

또는

app.use(function (req, res, next) {
    res.header('x-powered-by', 'Blood, sweat, and tears.');
    next();
  });
반응형