代码是:
const functions = require('firebase-functions'); // is installed automatically when you init the project
const { auth } = require('google-auth-library'); // is used to authenticate your request
async function exportDB () {
const admin = await auth.getClient({
scopes: [ // scopes required to make a request
'https://www.googleapis.com/auth/datastore',
'https://www.googleapis.com/auth/cloud-platform'
]
});
const projectId = await auth.getProjectId();
const url = `https://firestore.googleapis.com/v1beta1/projects/${projectId}/databases/(default):exportDocuments`;
return admin.request({
url,
method: 'post',
data: {
outputUriPrefix: 'gs://name-of-the-bucket-you-created-for-backups'
}
});
}
常量备份 = functions.pubsub.topic('YOUR_TOPIC_NAME_HERE').onPublish(exportDB); module.exports = { 备份 };
当我通过以下方式进行部署时:
gcloud functions deploy backup --runtime nodejs8 --trigger-topic YOUR_TOPIC_NAME_HERE
我得到错误:
错误: (gcloud.functions.deploy) OperationError: code=3, message=Function failed on loading user code。错误消息:无法加载文件 index.js 中的代码。您的代码中是否存在语法错误?
详细的堆栈跟踪:TypeError:无法读取未定义的属性“用户”
这是 google-auth-library 的东西吗?