google-cloud-functions - 如何在本地获取测试数据运行功能?
问题描述
我有以下内容:
export const helloWorld = functions.https.onRequest((request, response) => {
response.send(request.body);
});
我在本地运行它并运行helloWorld("Hey")
,这是输出:
firebase > helloWorld('HEY')
Sent request to function.
firebase > info: User function triggered, starting execution
info: Execution took 1 ms, user function completed successfully
RESPONSE RECEIVED FROM FUNCTION: 200, "{}"
为什么只有{}
当我清楚地发送一个字符串时它才输出?
解决方案
这不是您在本地调用 HTTP 类型函数的方式。您应该查看文档并使用其中建立的模式。您调用该方法,就好像您正在使用节点请求模块一样:
在 shell 中调用 HTTPS 函数,用法与 request NPM 模块相同,但将 request 替换为您要模拟的函数的名称。例如:
# invoke myHttpsFunction() myHttpsFunction.get() myHttpsFunction.post() # invoke at sub-path myHttpsFunction('/path') myHttpsFunction.get('/path') myHttpsFunction.post('/path') # send POST request with form data myHttpsFunction.post('/path').form( {foo: 'bar' })
我不确定您是否能够指定整个内容正文。这似乎是一种不常见的情况,因为您通常通过其查询字符串或表单编码主体将参数传递给 HTTP 函数。
推荐阅读
- java - 使用 Jackson 从单个文件中读取多个 JSON 对象
- vue.js - 将数据从模板传递到组件
- c++ - 自动完成在 git 存储库中的 Visual Studio 项目中不起作用
- android - 将 android studio 构建输出窗口文本更改为英文
- mysql - 选择每个对话的第一行
- javascript - Leaflet JS中的多个圆圈
- java - 我不理解java中的通配符
- python - TypeError: 不支持的操作数类型 /: 'Dimension' 和 'int'
- c - 如何在 flatbuffers 模式文件中声明指针类型?
- dialogflow-es - 尝试发布 alpha 时未找到对 google 测试指令的操作