【发布时间】:2020-02-29 07:22:46
【问题描述】:
服务器代码
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
exports.hello = functions.https.onCall((data, context) => {
console.log(data.text);
return 123;
});
客户端代码
const myFunc = firebase.functions().httpsCallable('hello');
myFunc({text: 'world'}).then((rslt)=>{
console.log('rslt:', rslt);
});
但这行不通。 我在客户端浏览器控制台收到错误消息。
访问 'https:// ==skip== /hello' 从源获取 'http://localhost:5000' 已被 CORS 策略阻止:响应 预检请求未通过访问控制检查:重定向未通过 允许预检请求。
我该如何解决这个问题? 我在谷歌指南文档中没有找到解决方案。
我看到 cmets 并添加内容。
查询未到达服务器。
如果我在功能部署后尝试,它可以正常工作。
但它不会显示在本地控制台上,而是显示在 firebase 控制台上。
如何进行本地服务器调用?
每次测试功能时都部署是很疯狂的。
【问题讨论】:
-
查询是否到达了服务器端的 console.log?
标签: firebase cors google-cloud-functions