๐Ÿ’ป์›น(Web)/React

[React]Firebase๋กœ React ๋ฐฐํฌํ•˜๊ธฐ, Mixed-Content ์—๋Ÿฌ

stonesy 2023. 9. 3. 14:51
728x90

Netlify๋กœ React ํ”„๋กœ์ ํŠธ๋ฅผ ๋ฐฐํฌํ•œ ์ดํ›„, ์—ฌ๋Ÿฌ๊ฐ€์ง€ ๋ฐฐํฌ๋ฐฉ๋ฒ•์„ ๊ณต๋ถ€ํ•ด๋ณด๊ณ  ์‹ถ์–ด์„œ Firebase๋ฅผ ์ด์šฉํ•ด React ํ”„๋กœ์ ํŠธ๋ฅผ ๋ฐฐํฌํ•˜๋Š” ๋ฐฉ๋ฒ•๋„ ์ •๋ฆฌํ•ด๋ณด์•˜๋‹ค๐Ÿ™Œ๐Ÿป

 

๐Ÿ”ŽFirebase

Firebase๋Š” ๊ฐœ๋ฐœ์„ ํŽธ๋ฆฌํ•˜๊ฒŒ ํ•ด์ฃผ๋Š” ํด๋ผ์šฐ๋“œ ๊ธฐ๋ฐ˜์˜ ๋ชจ๋ฐ”์ผ ๋ฐ ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ฐœ๋ฐœ ํ”Œ๋žซํผ์ด๋‹ค. ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ฐœ๋ฐœ ๊ณผ์ •์—์„œ ์‚ฌ์šฉ๋˜๋Š” ๊ธฐ๋Šฅ(์˜ˆ: ์‚ฌ์šฉ์ž์ธ์ฆ, DB, ๋ฐฐํฌ)๋“ค์„ ์ •ํ˜•ํ™”๋œ ์„œ๋น„์Šค๋กœ ์ œ๊ณตํ•จ์œผ๋กœ์จ ๊ฐœ๋ฐœ์ž๋“ค์ด ๋” ๋น ๋ฅด๊ณ  ํšจ์œจ์ ์œผ๋กœ ๊ฐœ๋ฐœํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•œ๋‹ค.

 

๐Ÿ”ŽFirebase๋ฅผ ํ†ตํ•ด React ํ”„๋กœ์ ํŠธ ๋ฐฐํฌํ•˜๊ธฐ

Firebase๊ฐ€ ์ œ๊ณตํ•˜๋Š” ๊ธฐ๋Šฅ๋“ค ์ค‘ ๋ฐฐํฌ ์„œ๋น„์Šค๋ฅผ ์ด์šฉํ•ด๋ณด๋„๋ก ํ•˜์ž.

 

1. ํ”„๋กœ์ ํŠธ ์ƒ์„ฑํ•˜๊ธฐ

์•„๋ž˜ ๋งํฌ์—์„œ “ํ”„๋กœ์ ํŠธ ๋งŒ๋“ค๊ธฐ”๋กœ ํ”„๋กœ์ ํŠธ๋ฅผ ์ƒ์„ฑํ•œ๋‹ค.

https://console.firebase.google.com/?hl=ko

 

๋กœ๊ทธ์ธ - Google ๊ณ„์ •

์ด๋ฉ”์ผ ๋˜๋Š” ํœด๋Œ€์ „ํ™”

accounts.google.com

ํ”„๋กœ์ ํŠธ ์ด๋ฆ„ ์ž…๋ ฅํ•˜๊ณ  ๊ณ„์† ๋„˜์–ด๊ฐ€๋ฉด ํ”„๋กœ์ ํŠธ๊ฐ€ ์ƒ์„ฑ๋œ๋‹ค.

ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ ํ›„์— ๋นŒ๋“œ>Hosting>์‹œ์ž‘ํ•˜๊ธฐ๋ฅผ ๋ˆ„๋ฅด๊ณ  ์„ค์ •์„ ๊ทธ๋Œ€๋กœ ๋”ฐ๋ผํ•˜๋ฉด ๋œ๋‹ค.

 

2. Firebase ํ˜ธ์ŠคํŒ… ์„ค์ •ํ•˜๊ธฐ

2-1) Firebase ํ˜ธ์ŠคํŒ… ์„ค์ •1: Firebase CLI ์„ค์น˜

๋จผ์ € npm ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด์„œ ํ•„์š”ํ•œ ๋„๊ตฌ๋ฅผ ์„ค์น˜ํ•œ๋‹ค.

 

2-2) Firebase ํ˜ธ์ŠคํŒ… ์„ค์ •2: ํ”„๋กœ์ ํŠธ ์ดˆ๊ธฐํ™”

์œ„์˜ ์„ค๋ช…๋Œ€๋กœ ํ„ฐ๋ฏธ๋„์— firebase login ์ž…๋ ฅํ•˜๊ณ  yes๋ฅผ ๋ˆ„๋ฅด๋ฉด ์ฐฝ์ด ๋œจ๋ฉด์„œ ๋กœ๊ทธ์ธ์ด ๊ฐ€๋Šฅํ•˜๋‹ค.

๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ํ„ฐ๋ฏธ๋„์— firebase init ์ž…๋ ฅํ•˜๋ฉด ๋œ๋‹ค. ๋ฐฐํฌ ์„œ๋น„์Šค๋ฅผ ์ด์šฉํ• ๊ฑฐ๋‹ˆ๊นŒ Hosting ์นธ์— ์ฒดํฌํ•ด์ฃผ๊ณ , Use an existing project๋ฅผ ์ฒดํฌํ•˜๊ณ  ๋„˜์–ด๊ฐ€๋ฉด ๋œ๋‹ค.

 

2-3) Firebase ํ˜ธ์ŠคํŒ… ์„ค์ •3: Firebase ํ˜ธ์ŠคํŒ…์— ๋ฐฐํฌ

๋ฐฐํฌ๊ฐ€ ์™„๋ฃŒ๋˜๋ฉด ์•„๋ž˜์— Hosting URL ํ•˜๊ณ  ~~web.app ์ฃผ์†Œ๊ฐ€ ๋œจ๋Š”๋ฐ ์ด ์ฃผ์†Œ๋กœ ๋“ค์–ด๊ฐ€๋ฉด ๋‚ด๊ฐ€ ๋ฐฐํฌํ•œ ํŽ˜์ด์ง€๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

 

์ฐฝ์—… ๋™์•„๋ฆฌ ์ค‘๊ฐ„ํ‰๊ฐ€ ๊ฒฐ๊ณผ๋ฌผ์„ ๋ฐฐํฌํ•  ๋•Œ, ๋‹ค๋ฅธ ํŒ€์›๋ถ„์ด Firebase๋ฅผ ์ด์šฉํ•œ ๋ฐฐํฌ๋„ ์‹œ๋„ํ•˜์…จ์—ˆ๋‹ค. ๊ทผ๋ฐ ๊ณ„์† ์˜ค๋ฅ˜๊ฐ€ ๋‚˜์„œ ์•Œ์•„๋ณด๋‹ˆ Firebase๋Š” https ์ฃผ์†Œ๋งŒ ํ—ˆ์šฉ๋˜๊ธฐ ๋•Œ๋ฌธ์— ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•œ ๊ฒƒ์ด๋ผ๊ณ  ์•Œ๋ ค์ฃผ์…จ๋‹ค. ์•„๋งˆ Mixed Content ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•œ ๊ฒƒ ๊ฐ™๋‹ค. ๋‹ค์Œ์— ๋” ๊นŠ๊ฒŒ ๊ณต๋ถ€ํ•ด๋ด์•ผ๊ฒ ๋‹ค๐Ÿ™Œ๐Ÿป

 

 

++์ถ”๊ฐ€

โ—Mixed Content ์—๋Ÿฌ

Mixed Content ์˜ค๋ฅ˜๋ž€ ์•”ํ˜ธํ™”๋œ https์—์„œ ์•”ํ˜ธํ™”๋˜์ง€ ์•Š์€ http์— ์š”์ฒญ์„ ๋ณด๋ƒˆ๊ธฐ ๋•Œ๋ฌธ์— ๋ฐœ์ƒํ•œ ์—๋Ÿฌ์ด๋‹ค. ์‚ฌ์‹ค Netlify๋กœ ์š”์ฒญ์„ ๋ณด๋ƒˆ์„ ๋•Œ๋„ ์ด ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ–ˆ์—ˆ๋Š”๋ฐ ๋‹ค๋ฅธ ์—๋Ÿฌ๋ฅผ ํ•ด๊ฒฐํ•˜๋‹ค๋ณด๋‹ˆ ํ•ด๊ฒฐ๋ผ์„œ ํฌ๊ฒŒ ์‹ ๊ฒฝ์„ ์•ˆ์“ฐ๊ณ  ์žˆ์—ˆ๋‹ค(?) ์–ด์จŒ๋“  ์œ„ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ์„œ๋ฒ„์—์„œ SSL ํ”„๋กœํ† ์ฝœ์„ ํ†ตํ•œ https๋ฅผ ์ง€์›ํ•ด์ฃผ์–ด์•ผ ํ•œ๋‹ค๊ณ  ํ•œ๋‹ค.

ํ˜น์€ React ํ”„๋กœ์ ํŠธ์˜ index.html์— ํ•ด๋‹น ์ฝ”๋“œ๋ฅผ ์ถ”๊ฐ€ํ•ด์ค˜์•ผ ํ•˜๋Š” ๊ฒƒ ๊ฐ™๋‹ค.

<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests" />

 

728x90