【问题标题】:Google Cloud Function Error - res.setHeader is not a function谷歌云函数错误 - res.setHeader 不是函数
【发布时间】:2017-12-23 22:48:06
【问题描述】:

我正在尝试从Cloud Functions Documentation 运行第一个示例。 我创建了我的函数,并从文档中复制并粘贴了示例。

更正:我从这里获取了示例代码: https://api.ai/docs/getting-started/basic-fulfillment-conversation

我收到的第一个错误是;

res.setHeader 不是函数

然后我尝试使用另一个函数来设置标题:

res.writeHead(200, { 'Content-Type': 'application/json' });

但这也给了我同样的错误。 这是我的以下代码;

/**
 * Cloud Function.
 *
 * @param {object} event The Cloud Functions event.
 * @param {function} callback The callback function.
 */
exports.helloHttp = function helloHttp(req, res) {
    response = "This is a sample response from your webhook!" //Default response from the webhook to show it's working

    // res.setHeader('Content-Type', 'application/json'); //Requires application/json MIME type
    res.writeHead(200, { 'Content-Type': 'application/json' });
    //"speech" is the spoken version of the response, "displayText" is the visual version
    res.send(JSON.stringify({
        "speech": response,
        "displayText": response        
    }));
};

并遵循它在测试控制台上的显示方式;

我错过了什么吗?

【问题讨论】:

    标签: node.js google-cloud-functions


    【解决方案1】:

    这是我的错误,我必须在创建时选择 HTTP 触发器。 现在可以正常使用了。

    【讨论】:

      猜你喜欢
      • 2020-10-25
      • 2018-04-19
      • 2020-05-01
      • 2019-06-28
      • 2021-06-23
      • 1970-01-01
      • 2019-02-15
      • 2018-12-07
      • 2018-10-02
      相关资源
      最近更新 更多