【发布时间】:2019-02-28 14:48:00
【问题描述】:
我正在按照 github 存储库中的示例来缩短链接 url
https://github.com/firebase/functions-samples/tree/Node-8/url-shortener
给出的错误如下
12:49:56.472米。 shortUrl 函数执行耗时 509 毫秒,完成 状态:'错误'12:49:56.464 a。米。缩短网址请求错误: 错误: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 [as _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 以便为 bitly 编译必要的
{
"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"
有什么线索吗?谢谢
【问题讨论】:
标签: firebase google-cloud-functions