0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

firebaseのfunctionでCORSしてるつもりないのにCORS関連で怒られたとき

Posted at

#CORSしてないつもりなのにCORSエラーを吐く

firebaseのfunction便利ですよね。
クライアントからfunction叩いた時に、CORSしてない(同一プロジェクト内のfunctionを叩いている)のに下記のエラーを吐いてしばらく困りました。

console.log
Access to fetch at 'functionのURL' from origin 'hostingのURL' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request.

##結論はただのミス

見出しの通りです。countUPというfunctionを呼び出そうとしていたのにcountUpと書いていたのが原因でした。

index.js
 const countUP= firebase.functions().httpsCallable('countUp')
 const countUP= firebase.functions().httpsCallable('countUP')

他にもfunctionの書き方でonCallonRequestとかによってCORS関連のエラーを吐く場合があるようなので
firebaseのドキュメントのアプリから関数を呼び出すのページも見てみてください
しっかりコードを見直しましょう!!(戒め)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?