firebase CORS ์—๋Ÿฌ Response to preflight request doesn't pass access control check ~
728x90

์–ด๋–ค ์—๋Ÿฌ?

ํŒŒ์ด์–ด๋ฒ ์ด์Šค ์Šคํ† ๋ฆฌ์ง€์— ์ด๋ฏธ์ง€ ์—…๋กœ๋“œ๋ฅผ ๊ตฌํ˜„ํ•˜๋˜ ์ค‘ CORS ์—๋Ÿฌ๋ฅผ ๋งŒ๋‚˜๊ฒŒ ๋˜์—ˆ๋‹ค.

 

Access to XMLHttpRequest at '~~' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

 

์›์ธ ํŒŒ์•…

๊ต์ฐจ ์ถœ์ฒ˜ ๋ฆฌ์†Œ์Šค ๊ณต์œ  (Cross-origin resource sharing)๊ฐ€ ํ—ˆ์šฉ์ด ๋˜์–ด์žˆ์ง€ ์•Š์•„์„œ ์ƒ๊ธด ์˜ค๋ฅ˜!..

CORS ์—๋Ÿฌ๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ํด๋ผ์ด์–ธํŠธ ์ชฝ์—์„œ๋„ ์ฒ˜๋ฆฌ๋ฅผ ํ•ด์ค˜์•ผ ํ•˜์ง€๋งŒ ์„œ๋ฒ„ ์ชฝ์—์„œ๋„ ์ฒ˜๋ฆฌ๋ฅผ ํ•ด์ฃผ์–ด์•ผ ํ•œ๋‹ค.

์ง€๊ธˆ ๊ฐ™์€ ๊ฒฝ์šฐ๋Š” ํŒŒ์ด์–ด๋ฒ ์ด์Šค ์„œ๋ฒ„ ์ชฝ์—์„œ CORS ์„ค์ •์„ ํ•ด๋ณด๊ธฐ๋กœ ํ–ˆ๋‹ค.

 

 

ํ•ด๊ฒฐ ๊ณผ์ •

https://console.cloud.google.com/

 

Google ํด๋ผ์šฐ๋“œ ํ”Œ๋žซํผ

๋กœ๊ทธ์ธ Google ํด๋ผ์šฐ๋“œ ํ”Œ๋žซํผ์œผ๋กœ ์ด๋™

accounts.google.com

 

 

๋จผ์ € ํด๋ผ์šฐ๋“œ ์ฝ˜์†”์— ๋“ค์–ด๊ฐ„๋‹ค.

์ƒ๋‹จ์—์„œ ํ˜„์žฌ ํŒŒ์ด์–ด๋ฒ ์ด์Šค ํ”„๋กœ์ ํŠธ๋ฅผ ์„ ํƒํ•œ ํ›„์—, ๊ฒ€์ƒ‰์ฐฝ ๋ฐ”๋กœ ์˜ค๋ฅธ์ชฝ์˜ ํ„ฐ๋ฏธ๋„ ํ™œ์„ฑํ™” ๋ฒ„ํŠผ ํด๋ฆญํ•œ๋‹ค.

 

 

๊ทธ๋Ÿผ ๋ธŒ๋ผ์šฐ์ € ํ•˜๋‹จ์— ์•„๋ž˜์™€ ๊ฐ™์€ ํ„ฐ๋ฏธ๋„ ์ฐฝ์ด ์—ด๋ฆฌ๋Š”๋ฐ, ํŽธ์ง‘๊ธฐ ์—ด๊ธฐ๋ฅผ ๋ˆ„๋ฅด๋ฉด GUI๋กœ ํŒŒ์ผ์„ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค.

 

 

์›ํ•˜๋Š” ๋„๋ฉ”์ธ๋งŒ ์ถ”๊ฐ€ํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด * ๋Œ€์‹ ์— ๋ฐฐ์—ด์—๋‹ค ๋„๋ฉ”์ธ์„ ์ถ”๊ฐ€ํ•ด ์ค€๋‹ค. ["https://example.com"\]

[
  {
 "origin": ["*"],
 "method": ["GET"],
 "maxAgeSeconds": 3600
  }
]

 

 

json ํŒŒ์ผ๋กœ ์ €์žฅ์„ ํ•ด์ค€๋‹ค. ํŒŒ์ผ๋ช…์€ ์ž์œ ์ง€๋งŒ ๋ณดํ†ต cors.json ์ด๋ผ๊ณ  ์ €์žฅํ•˜๋Š” ๋“ฏํ•˜๋‹ค.

 

 

๋‹ค์‹œ ์ฝ˜์†” ํ„ฐ๋ฏธ๋„์„ ์—ด๊ณ , ์•„๋ž˜ ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•ด ์ค€๋‹ค.

gsutil cors set cors.json gs:์Šคํ† ๋ฆฌ์ง€์ฃผ์†Œ

 

์ฐธ๊ณ ๋กœ ์Šคํ† ๋ฆฌ์ง€ ์ฃผ์†Œ๋Š” ์Šคํ† ๋ฆฌ์ง€์—์„œ ์‰ฝ๊ฒŒ ์ฐพ์„ ์ˆ˜ ์žˆ๋‹ค.

 

 

์œ„ ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ๋ฉด ์ด๋Ÿฐ ์Šน์ธ ์ฐฝ์ด ํ•˜๋‚˜ ๋œฌ๋‹ค.

 

 

์Šน์ธํ•˜๋ฉด ํ„ฐ๋ฏธ๋„์— ์•„๋ž˜์™€ ๊ฐ™์€ ๋ฉ”์‹œ์ง€๊ฐ€ ๋œจ๊ณ  CORS ์—๋Ÿฌ๊ฐ€ ์‚ฌ๋ผ์ง„๋‹ค!

Setting CORS on gs://์Šคํ† ๋ฆฌ์ง€์ฃผ์†Œ

 

 

 

CORS ์—๋Ÿฌ์— ๋Œ€ํ•ด ์ž ๊น ๊ณต๋ถ€ํ•˜๊ณ  ๋‚˜๋‹ˆ ์™œ ๋ฐœ์ƒํ•œ ๊ฒƒ์ธ์ง€ ์ง์ž‘์ด ์ข€ ๊ฐ€์„œ ์–ด๋ ต์ง€ ์•Š๊ฒŒ ํ•ด๊ฒฐํ–ˆ๋˜ ๊ฒƒ ๊ฐ™๋‹ค. ๐Ÿค”

 

 

 

์ฐธ๊ณ ๊ธ€

https://stove99.github.io/etc/2021/06/09/firebase-storage-cors-setting/

728x90