본문 바로가기

유통기한 관리_개인프로젝트

CORS for multiple origins

cors npm 패키지는 origin value에 대한 함수를 작성하는 옵션을 제공한다.

여러 도메인에 대해 CORS를 활성화하는 데 도움이 된다.

const cors = require('cors');
const allowedDomains = ["http://localhost:3000", "https://d-day.netlify.app"]
app.use(cors({
  origin: function(origin, callback) {
    if(!origin) return callback(null, true);
    if(allowedDomains.indexOf(origin) === -1) {
      const msg = `This site ${origin} does not have an access. Only specific domains are allowed to access it.`;
      return callback(new Error(msg), false);
    }
    return callback(null, true);
  }
})); 

'유통기한 관리_개인프로젝트' 카테고리의 다른 글

heroku 서버 - 이미지 업로드 오류 발생 - 이미지 직접 호스팅  (0) 2021.04.16
배포하기  (0) 2021.04.12
Suspense가 뭔가요?  (0) 2021.04.08
CORS 처리  (0) 2021.04.02
mongoose '__v' 필드  (0) 2021.04.01