Typescript 使用Firebase函数发出http请求时未找到地址
我已经使用Dialogflow为Google操作设置了Firebase函数,该函数使用Typescript 使用Firebase函数发出http请求时未找到地址,typescript,google-cloud-functions,dialogflow-es,actions-on-google,node-fetch,Typescript,Google Cloud Functions,Dialogflow Es,Actions On Google,Node Fetch,我已经使用Dialogflow为Google操作设置了Firebase函数,该函数使用节点获取进行API调用,但是当我发出实际请求时遇到了问题。即使我可以在浏览器中访问URL,但在函数运行时也无法解析它 错误: {"message":"request to https://jsonplaceholder.typicode.com/users failed, reason: getaddrinfo ENOTFOUND jsonplaceholder.typicode.com jsonplaceho
节点获取
进行API调用,但是当我发出实际请求时遇到了问题。即使我可以在浏览器中访问URL,但在函数运行时也无法解析它
错误:
{"message":"request to https://jsonplaceholder.typicode.com/users failed, reason: getaddrinfo ENOTFOUND jsonplaceholder.typicode.com jsonplaceholder.typicode.com:443","type":"system","errno":"ENOTFOUND","code":"ENOTFOUND"}
import * as functions from 'firebase-functions';
import fetch from 'node-fetch';
export const fetchTrainTimetable = async (): Promise<object> => {
const path = `https://jsonplaceholder.typicode.com/users`
try {
const response = await fetch(path, {method: 'GET'});
return await response.json();
} catch (error) {
return error;
}
}
代码:
{"message":"request to https://jsonplaceholder.typicode.com/users failed, reason: getaddrinfo ENOTFOUND jsonplaceholder.typicode.com jsonplaceholder.typicode.com:443","type":"system","errno":"ENOTFOUND","code":"ENOTFOUND"}
import * as functions from 'firebase-functions';
import fetch from 'node-fetch';
export const fetchTrainTimetable = async (): Promise<object> => {
const path = `https://jsonplaceholder.typicode.com/users`
try {
const response = await fetch(path, {method: 'GET'});
return await response.json();
} catch (error) {
return error;
}
}
import*作为“firebase函数”中的函数;
从“节点获取”导入获取;
export const fetchtrainthedule=async():Promise=>{
常量路径=`https://jsonplaceholder.typicode.com/users`
试一试{
const response=wait fetch(路径,{method:'GET'});
return wait response.json();
}捕获(错误){
返回误差;
}
}
为了使用Firebase函数发出出站请求,我是否需要在请求中包含缺少的内容?路径是什么似乎并不重要,我总是以这个错误结束 问题在于,您在默认的“spark”计划下使用Firebase功能,该计划是免费的,但有一个限制,即它不能访问Google以外的web或网络服务 您可以选择“blaze”计划,该计划允许网络访问,但需要您注册信用卡并收取使用费用。然而,即使在blaze计划中,也有一个免费的层,他们不会向您收费。这个空闲层通常足以用于试验、初始开发和早期部署下的使用。一旦你被部署,谷歌助手会提供云积分,这也会抵消这一点