如何使用 ReactJS 应用开发和测试 Firebase Callable 函数?
How to develop and test Firebase Callable functions with ReactJS app?
我有一个带有 Firebase 后端的 ReactJs 应用程序,我想在我的应用程序中使用 https.onCall。我用 firebase serve --only functions
开始我的功能
我有这个日志
functions: HTTP trigger initialized at
http://localhost:5000/dental2-test/us-central1/addReportSQL
addReportSQL 是我的功能
exports.addReportSQL = functions.https.onCall((data = 'TEST') => {
console.log('TEST!!!') // Need to call cloud sql db
return data
})
并在 React 应用程序 firebase 中拥有此代理
if (process.env.NODE_ENV === 'development')
app.functions().useFunctionsEmulator('http://localhost:5000')
如果我尝试从我的应用程序调用它,它似乎不起作用
<Button onClick={() => firebase.addReportSQL('Data')} />
我的目标是从此函数调用 Google SQL 云服务的查询。
如何针对本地环境进行正确设置?
这个设置是正确的,诀窍是首先声明这个函数
const testCall = firebase.addReportSQL(data)
testCall()
.catch(error => console.log(error))
.then(result => console.log(result))
我有一个带有 Firebase 后端的 ReactJs 应用程序,我想在我的应用程序中使用 https.onCall。我用 firebase serve --only functions
开始我的功能
我有这个日志
functions: HTTP trigger initialized at http://localhost:5000/dental2-test/us-central1/addReportSQL
addReportSQL 是我的功能
exports.addReportSQL = functions.https.onCall((data = 'TEST') => {
console.log('TEST!!!') // Need to call cloud sql db
return data
})
并在 React 应用程序 firebase 中拥有此代理
if (process.env.NODE_ENV === 'development')
app.functions().useFunctionsEmulator('http://localhost:5000')
如果我尝试从我的应用程序调用它,它似乎不起作用
<Button onClick={() => firebase.addReportSQL('Data')} />
我的目标是从此函数调用 Google SQL 云服务的查询。
如何针对本地环境进行正确设置?
这个设置是正确的,诀窍是首先声明这个函数
const testCall = firebase.addReportSQL(data)
testCall()
.catch(error => console.log(error))
.then(result => console.log(result))