Firebase Cloud Functions的示例抛出错误

时间:2018-09-25 03:57:46

标签: firebase google-cloud-functions

我正在跟踪github存储库中的示例,以缩短链接网址

https://github.com/firebase/functions-samples/tree/Node-8/url-shortener

以下给出的错误

  

12:49:56.472一个米shortUrl函数执行耗时509毫秒,已完成   状态:“错误” 12:49:56.464 a。米shortUrl RequestError:   错误:getaddrinfo EAI_AGAIN api-ssl.bitly.com:443       在新的RequestError(/srv/node_modules/request-promise-core/lib/errors.js:14:15)       在Request.plumbing.callback(/srv/node_modules/request-promise-core/lib/plumbing.js:87:29)       在Request.RP $ callback [作为_callback](/srv/node_modules/request-promise-core/lib/plumbing.js:46:31)       在self.callback(/srv/node_modules/request/request.js:185:22)       在emitOne上(events.js:116:13)       在Request.emit(events.js:211:7)       在Request.onRequestError(/srv/node_modules/request/request.js:881:8)       在emitOne上(events.js:116:13)       在ClientRequest.emit(events.js:211:7)       在TLSSocket.socketErrorListener(_http_client.js:387:9)       在emitOne上(events.js:116:13)       在TLSSocket.emit(events.js:211:7)       在emitErrorNT上(internal / streams / destroy.js:64:8)       在_combinedTickCallback(内部/进程/next_tick.js:138:11)       在process._tickDomainCallback(internal / process / next_tick.js:218:9)

我对函数确实很陌生,但是我确实按照那里的文档中的所有步骤进行操作。

这是我的函数文件夹中的index.js

const functions = require('firebase-functions');
const BitlyClient = require('bitly');
// TODO: Make sure to set the bitly.access_token cloud functions config using the CLI.
const bitly = BitlyClient(functions.config().bitly.access_token);

// Shorten URL written to /links/{linkID}.
exports.shortenUrl = functions.database.ref('/links/{linkID}').onCreate(async (snap) => {
  const originalUrl = snap.val();
  const response = await bitly.shorten(originalUrl);
  return snap.ref.set({
    original: originalUrl,
    short: response.data.url,
  })
});

和我的package.json,以编译必要的位

{
  "name": "url-shortener-functions",
  "description": "URL Shortener Firebase Functions sample",
  "dependencies": {
    "bitly": "^5.1.7",
    "firebase-admin": "~6.0.0",
    "firebase-functions": "^2.0.5"
  },
  "devDependencies": {
    "eslint": "^4.13.1",
    "eslint-plugin-promise": "^3.6.0"
  },
  "scripts": {
    "lint": "./node_modules/.bin/eslint --max-warnings=0 .",
    "serve": "firebase serve --only functions",
    "shell": "firebase experimental:functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "engines": {
    "node": "8"
  },
  "private": true
}

我也在函数文件夹中做了npm -install bitly,但仍然抛出该错误

我也根据文档说明在数据库中添加了链接

/functions-project-12345
    /links
        link-123456: "https://my.super.long-link.com/api/user/profile/-jEHitne10395-k3593085"

有任何线索吗?谢谢

1 个答案:

答案 0 :(得分:2)

它抱怨无法为远程主机解析:

RequestError: Error: getaddrinfo EAI_AGAIN api-ssl.bitly.com:443

因此,我假设需要paid plan才能执行此外部API调用。