首页 > 解决方案 > 使用 BODY 的 Google Cloud Functions 自定义 URL 重定向

问题描述

我正在使用具有自定义域的 Google Cloud Functions 来触发这些功能。然后我在执行过程中意识到了一些非常糟糕的事情。使用普通 URL ( https://us-central1-project.cloudfunctions.net/function),我的请求会保留其标头和正文,我可以将数据发送到我的函数。

但是,使用 firebase 重定向后,所有请求都是文本/纯文本GET请求,其中content-type没有数据;完全是空的。

有没有一种方法可以在我的云函数中获取这些数据,同时仍然为我的函数使用自定义 URL?

在寻找这个时,我遇到了这个问题>>为谷歌云功能使用自定义域<<我回答了我如何添加我的自定义 URL。这正是我使用它的方式。

这是我的函数调试代码

def function(request)

    content_type = request.headers['content-type']
    data = "not processed"

    if 'application/json' in content_type:
        data = str( request.get_json(force=True) )
    elif 'text/plain' in content_type:
        data = request.data.decode()
    else:
        return redirect('https://tradingview.to')

    print(data)
    return data

标签: google-cloud-functionsfirebase-hosting

解决方案


推荐阅读