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

How do I get test data running functions locally?

我有以下内容:

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 类型函数的方式。您应该查看 documentation 并使用那里建立的模式。您像使用节点请求模块一样调用该方法:

For invoking HTTPS functions in the shell, usage is the same as the request NPM module, but replace request with the name of the function you want to emulate. For example:

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