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

πŸ”§ [WV-46] fix : Mixed Content Error ν•΄κ²° #52

Merged
merged 6 commits into from
Jan 16, 2025

Conversation

Jinviz
Copy link
Member

@Jinviz Jinviz commented Jan 16, 2025

κ°œμš”

저희 배포된 μ•±μ—μ„œ λ°±μ—”λ“œ λ‘œμ§μ„ 뢈러올 수 μ—†μ—ˆλ˜ 였λ₯˜λ₯Ό μˆ˜μ •ν•˜μ˜€μŠ΅λ‹ˆλ‹€.


PR Checklist

PR이 λ‹€μŒ μš”κ΅¬ 사항을 μΆ©μ‘±ν•˜λŠ”μ§€ ν™•μΈν•˜μ„Έμš”.

  • PR 제λͺ© 및 컀밋 λ©”μ‹œμ§€ μ»¨λ²€μ…˜ 확인
  • 직접 λ§Œλ“  ν•¨μˆ˜κ°€ μžˆλ‹€λ©΄ 이에 λŒ€ν•œ μ„€λͺ… μΆ”κ°€ (ex. JS DOCS)
  • λ³€κ²½ 사항에 λŒ€ν•œ ν…ŒμŠ€νŠΈ μ™„λ£Œ (버그 μˆ˜μ •/κΈ°λŠ₯에 λŒ€ν•œ ν…ŒμŠ€νŠΈ)
  • Label 확인
  • Assignees μ„€μ • 확인
  • Reviewers μ„€μ • 확인

PR details

1. Mixed Content λ¬Έμ œλž€?

Mixed ContentλŠ” λ³΄μ•ˆμ΄ κ°•ν™”λœ HTTPS νŽ˜μ΄μ§€κ°€ λ³΄μ•ˆμ΄ μ•½ν•œ HTTP λ¦¬μ†ŒμŠ€λ₯Ό λ‘œλ“œν•˜λ €κ³  ν•  λ•Œ λ°œμƒν•©λ‹ˆλ‹€. Vercel은 HTTPS둜 앱을 μ œκ³΅ν•˜λŠ”λ°, HTTP λ°±μ—”λ“œλ‘œ 직접 μš”μ²­μ„ 보내면 λΈŒλΌμš°μ €κ°€ 이λ₯Ό λ³΄μ•ˆ μœ„ν˜‘μœΌλ‘œ μΈμ‹ν•˜μ—¬ ν•΄λ‹Ή μš”μ²­μ„ μ°¨λ‹¨ν•˜κ²Œ λ©λ‹ˆλ‹€. 이와 같은 λ¬Έμ œκ°€ λ°±μ—”λ“œ λ‘œμ§μ„ 뢈러올 수 μ—†μ—ˆλ˜ μ΄μœ μ˜€μŠ΅λ‹ˆλ‹€.

2. ν•΄κ²° 방법

./next.config.mjs

const nextConfig = {
  reactStrictMode: true,
  async rewrites() {
    return [
      {
        source: "/:path*", // λͺ¨λ“  /api/* μš”μ²­μ„ ν”„λ‘μ‹œ
        destination: `${process.env.NEXT_PUBLIC_API_URL}/:path*`, // μ‹€μ œ API μ„œλ²„λ‘œ μš”μ²­ 전달
      },
    ];
  },
}

ν”„λ‘μ‹œλ₯Ό ν†΅ν•œ 우회 방법

Next.js μ„€μ • νŒŒμΌμ—μ„œ ν•΄λ‹Ή κΈ°λŠ₯을 μΆ”κ°€ν•˜μ˜€μŠ΅λ‹ˆλ‹€. κ°„λ‹¨νžˆ λ§ν•΄μ„œ URL ν”„λ‘μ‹œ 섀정을 ν•¨μœΌλ‘œμ¨ ν΄λΌμ΄μ–ΈνŠΈκ°€ μ§μ ‘μ μœΌλ‘œ λ°±μ—”λ“œ URL둜 μ ‘κ·Όν•˜μ§€ μ•Šκ³  Next μ„œλ²„μ˜ ν”„λ‘μ‹œλ₯Ό 톡해 λ°±μ—”λ“œ 경둜둜 requestκ°€ μ²˜λ¦¬λ©λ‹ˆλ‹€.

쑰금 더 μžμ„Ένžˆ μ„€λͺ…λ“œλ¦¬μžλ©΄...

rewrites 섀정은 ν΄λΌμ΄μ–ΈνŠΈμ—μ„œ 직접 HTTP λ°±μ—”λ“œλ‘œ μš”μ²­μ„ λ³΄λ‚΄λŠ” λŒ€μ‹ 
Next.js 미듀웨어가 μ€‘κ°„μ—μ„œ ν”„λ‘μ‹œ 역할을 ν•˜μ—¬ λ°±μ—”λ“œλ‘œ μš”μ²­μ„ μ „λ‹¬ν•˜κ²Œ λ©λ‹ˆλ‹€
μ΄λ ‡κ²Œ ν•˜λ©΄ ν΄λΌμ΄μ–ΈνŠΈ-μ„œλ²„ κ°„ 톡신은 HTTPS둜 μœ μ§€λ˜λ©΄μ„œ, μ„œλ²„-λ°±μ—”λ“œ κ°„ 톡신은 HTTP둜 μ΄λ£¨μ–΄μ§ˆ 수 μžˆμŠ΅λ‹ˆλ‹€
μ΄λ ‡κ²Œ Next.jsκ°€ λ―Έλ“€μ›¨μ–΄λ‘œμ¨ URL ν”„λ‘μ‹œν•  수 μžˆλŠ” 것은 μ„œλ²„λ¦¬μŠ€ ν•¨μˆ˜κ°€ λ™μž‘ν•˜κΈ° λ•Œλ¬Έμ΄λΌκ³  ν•˜λ„€μš”.. (λ³΅μž‘μ“°)

κ²°λ‘ 

이제 /api/* 둜 λ³΄λ‚΄λŠ” μš”μ²­μ€ λͺ¨λ‘ {{BASE_URL}}/api/* 둜 rewrite 되기 λ•Œλ¬Έμ—, fetch에 API 경둜λ₯Ό 적어쀄 λ•Œλ„ BASE_URL을 적지 μ•Šμ•„λ„ λ©λ‹ˆλ‹€. κ·Έλ ‡κΈ° λ•Œλ¬Έμ— μ§€κΈˆκΉŒμ§€ api.ts κ΅¬ν˜„λ˜μ—ˆλ˜ fetch URL을 μˆ˜μ •ν•˜μ˜€μŠ΅λ‹ˆλ‹€.

μ§€κΈˆλΆ€ν„° fetch ν•˜μ‹€ λ•ŒλŠ” BASE_URL을 적지 μ•Šκ³ , λ°”λ‘œ API μ—”λ“œν¬μΈνŠΈλ§Œ μ μ–΄μ£Όμ‹œλ©΄ λ©λ‹ˆλ‹€! (/api/~~)
ν™˜κ²½λ³€μˆ˜λ„ 각자 λ‘œμ»¬μ—μ„œ μˆ˜μ •ν•΄μ£Όμ‹œκΈΈ λ°”λžλ‹ˆλ‹€.

NEXT_PUBLIC_KAKAO_API_KEY = cc7c596f752d18343b2f0575e776aa78
NEXT_PUBLIC_API_KEY = 54.180.228.165

μ˜ˆμ‹œ

이전

const res = await fetch(
      `${BASE_URL}/game/monthschedule?yearMonth=${params}`
    );

이후

const res = await fetch(
      '/api/game/monthschedule?yearMonth=${params}'
    );

참고 자료

https://velog.io/@deli-ght/nextrewrite%EC%99%80-redirect
https://nextjs-ko.org/docs/app/api-reference/next-config-js/rewrites


When modifying code...

# Request Level
  - [ ] : "πŸ”₯ μ΄λŒ€λ‘œ Merge ν•˜λ©΄ μ•ˆλΌμš”~!"
  - [ ] : "πŸ₯Ή 고치면 λΆ„λͺ… λ‚˜μ•„μ§ˆ 게 λΆ„λͺ…ν•©λ‹ˆλ‹€.."
  - [ ] : "🀷 μˆ˜μ •ν•˜λ©΄ 쒋지 μ•Šμ„κΉŒμš”?"

# Description

@Jinviz Jinviz self-assigned this Jan 16, 2025
@Jinviz Jinviz added fix λ²„κ·Έμˆ˜μ • setting ν”„λ‘œμ νŠΈ μ…‹νŒ… labels Jan 16, 2025
@hee2323 hee2323 changed the title πŸ”§ [WV-46] fix : Mixed Content Error ν•΄ πŸ”§ [WV-46] fix : Mixed Content Error ν•΄κ²° Jan 16, 2025
Copy link
Contributor

@hee2323 hee2323 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

κ³ μƒν•˜μ…¨μŠ΅λ‹ˆλ‹€πŸ‘πŸ»

Copy link
Contributor

@hayoung78 hayoung78 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ν™•μΈν–ˆμŠ΅λ‹ˆλ‹€!

@Jinviz Jinviz merged commit 536053c into dev Jan 16, 2025
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix λ²„κ·Έμˆ˜μ • setting ν”„λ‘œμ νŠΈ μ…‹νŒ…
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants