如何获取本地运行的测试数据?

时间:2019-02-08 01:01:52

标签: google-cloud-functions firebase-cli

我有以下内容:

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, "{}"

为什么当我明确给它发送一个字符串时它只输出{}

1 个答案:

答案 0 :(得分:2)

这不是您在本地调用HTTP类型函数的方式。您应该查看documentation并使用在那里建立的模式。您就像使用节点请求模块一样调用该方法:

  

要在外壳中调用HTTPS函数,用法与   请求NPM模块,但将请求替换为函数名称   你想效仿。例如:

# 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函数。

相关问题