localhostで起動しているページからFirebaseの関数経由でCloud Functionsのデータが取得できません。
コールすると Error: Response is missing data field. となります。
Cloud FunctionのREST APIをcurlやブラウザからコールした場合は問題なくデータを取得することができます。
■ 環境
ドメイン: localhost
ブラウザ: Chrome
コードは以下の通りです。
■ クライアント側(localhost)
TypeScript
1 public send () { 2 let api = firebase.functions().httpsCallable('helloWorld') 3 api({text: 'test'}).then((result) => { 4 console.log(result.data) 5 }).catch((error) => { 6 console.error(error) 7 }) 8 }
■ サーバー側(Cloud Function)
TypeScript
1import * as functions from 'firebase-functions' 2export const helloWorld = functions.https.onRequest((request, response) => { 3 // response.header('Accept', '/') 4 // response.header('withCredentials', 'true') 5 response.header('Content-Type','application/json') 6 response.header('Access-Control-Allow-Origin', '*') 7 response.header('Access-Control-Allow-Credentials', 'true') 8 response.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, X-Access-Token", Authorization') 9 const jsonData = { 10 id: 1, 11 comment: 'Hello world.' 12 } 13 response.status(200).json(jsonData).end() 14})
サーバー側のheaderに足りていない設定があるのでしょうか。
お手数ですがご教授お願い致します。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。