Firebase Cloud Functions使用NPM 8部署异步功能

时间:2018-08-13 14:29:03

标签: firebase async-await google-cloud-functions

我的功能package.json

...
"dependencies": {
    "firebase-admin": "~5.13.0",
    "firebase-functions": "^2.0.0",
    "puppeteer": "^1.6.2"
},
"engines": {
    "node": "8"
}

我以前的非异步功能得到了部署。但不是我的新异步对象:

exports.screenshot = async  (req, res) => {
  const url = "https://google.de"; // req.query.url;

  if (!url) {
    return res.send('Please provide URL as GET parameter, for example: <a href="?url=https://example.com">?url=https://example.com</a>');
  }

  const browser = await puppeteer.launch({
    args: ["--no-sandbox"]
  });
  const page = await browser.newPage();
  await page.goto(url);
  const imageBuffer = await page.screenshot();
  await browser.close();

  res.set("Content-Type", "image/png");
  res.send(imageBuffer);
};

运行时:firebase deploy --only functions:screenshot 我收到错误消息:

The following functions are found in your project but do not exist in your local source code:
        screenshot(us-central1)

我该怎么办?

1 个答案:

答案 0 :(得分:0)

exports.screenshot = functions.https.onRequest(async (req, res) => {
...
});

为我做了