Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix login #17

Merged
merged 2 commits into from
Oct 17, 2023
Merged

Hotfix login #17

merged 2 commits into from
Oct 17, 2023

Conversation

UnhappyDogChew
Copy link

로그인 관련해서 CORS 문제가 발생해서 여러가지 방법을 모색해 봤지만, 결국 rewrite 기능을 이용하는게 가장 간단하고 좋은 방법인 것 같습니다. 하지만 rewrite로 Next.js 서버를 프록시처럼 이용하게 되면 불필요한 트래픽이 Next.js서버에 계속 걸리는 셈이 되므로 나중에 성능 최적화를 할 필요가 있을때 개선해야할 부분인 것 같습니다.

rewrite 적용 후 map.js 파일에서 axios 요청 관련 문제가 발생했는데, map.js 페이지는 SSR로 구현해서 브라우저 환경이 아닌 Node.js환경에서 axios 코드가 실행되는 바람에 rewrite가 적용되지 않아 발생하는 문제였습니다. 그래서 런타임 환경이 브라우저인지 체크하는 함수를 구현하고, 브라우저 환경이 아니라면 url을 바꿔주는 식으로 일단 해결했습니다.

아래는 주요 변경사항이니 확인 부탁드려요!

- rewrite로 /api url로 들어오는 요청을 api 서버로 포워딩하도록 설정
- 런타임 환경이 브라우저인지 체크하는 isBrowser() 함수를
  utils/environment.js 모듈에 추가
- /service/building.service.js에서 호스트 url을 결정할 때 런타임 환경이
  브라우저인지 확인하여 다른 url로 설정되도록 함. 서버사이드 렌더링을 할
때 rewrite가 적용되지 않는 문제를 해결하기 위한 조치
- 기존의 NEXT_PUBLIC_API_HOST 환경변수를 사용하던 코드들을 /api url을
  사용하도록 변경

- rewrite로 /api url로 들어오는 요청을 api 서버로 포워딩하도록 설정
- 런타임 환경이 브라우저인지 체크하는 isBrowser() 함수를
  utils/environment.js 모듈에 추가
- /service/building.service.js에서 호스트 url을 결정할 때 런타임 환경이
  브라우저인지 확인하여 다른 url로 설정되도록 함. 서버사이드 렌더링을 할
때 rewrite가 적용되지 않는 문제를 해결하기 위한 조치
- 기존의 NEXT_PUBLIC_API_HOST 환경변수를 사용하던 코드들을 /api url을
  사용하도록 변경
@UnhappyDogChew UnhappyDogChew changed the base branch from main to refactor-0.0.1 October 15, 2023 12:14
@injulme injulme merged commit 7317b41 into refactor-0.0.1 Oct 17, 2023
@UnhappyDogChew UnhappyDogChew deleted the hotfix-login branch October 17, 2023 07:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants