我正在尝试将第二代 Google Cloud Function(触发事件类型)部署为模块,因为我需要使用 import 语句。
问题是GCP找不到入口点 我应该如何修改以下代码?
index.js
const functions = require('@google-cloud/functions-framework');
// Register a CloudEvent callback with the Functions Framework that will
// be executed when the Pub/Sub trigger topic receives a message.
functions.cloudEvent('printPDFFromHTMLtest2', cloudEvent => {
// The Pub/Sub message is passed as the CloudEvent's data payload.
const base64name = cloudEvent.data.message.data;
const name = base64name
? Buffer.from(base64name, 'base64').toString()
: 'World';
console.log(`Hello, ${name}!`);
});
package.json
{
"dependencies": {
"@google-cloud/functions-framework": "^3.0.0"
}
}
我已经找到解决办法了。
package.json
{
"dependencies": {
"@google-cloud/functions-framework": "^3.0.0"
},
"type":"module"
}
index.js
import functions from '@google-cloud/functions-framework';
export const printPDFFromHTMLtest2 = functions.cloudEvent('printPDFFromHTMLtest2', cloudEvent => {
// The Pub/Sub message is passed as the CloudEvent's data payload.
const base64name = cloudEvent.data.message.data;
const name = base64name
? Buffer.from(base64name, 'base64').toString()
: 'World';
console.log(`Hello, ${name}!`);
});