Firebase Cloud Functions-从https可调用函数

时间:2020-05-12 01:12:59

标签: firebase google-cloud-functions

我有一个云功能,可以发送自定义电子邮件验证电子邮件,该电子邮件包含一个重定向到我的网站的链接。我的问题是,当我在localhost上进行测试时,重定向URL转到生产站点。我知道这是预期的行为。

是否可以使用https可调用函数接收的context数据获取原始URL来生成更特定的重定向URL?

我无法对context对象进行字符串化处理,而没有收到TypeError: Converting circular structure to JSON错误,但是当我将其记录到控制台时,在firebase控制台中的cloud函数日志中,我在JSON的深处看到了原始URL。对象。

控制台中的代码段

headers: 
      { host: 'us-central1-universal-alert.cloudfunctions.net',
        'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36',
        'transfer-encoding': 'chunked',
        accept: '*/*',
        'accept-encoding': 'gzip, deflate, br',
        'accept-language': 'en-GB,en-US;q=0.9,en;q=0.8,fr;q=0.7',
        authorization: 'Bearer eyJhbGciOiJSUzI1NiIsImtpZCI6ImZjMmM4YmIyNmE3OGM0M2JkODYzNzA1YjNkNzkyMWI0ZTY0MjVkNTQiLCJ0eXAiOiJKV1QifQ.eyJpc3MiOiJodHRwczovL3NlY3VyZXRva2VuLmdvb2dsZS5jb20vdW5pdmVyc2FsLWFsZXJ0IiwiYXVkIjoidW5pdmVyc2FsLWFsZXJ0IiwiYXV0aF90aW1lIjoxNTg5MjQ0MDg3LCJ1c2VyX2lkIjoiNjJwaGJmQTRvTVUyT3E5aVpzSm5zZXZNd2hNMiIsInN1YiI6IjYycGhiZkE0b01VMk9xOWlac0puc2V2TXdoTTIiLCJpYXQiOjE1ODkyNDQwODcsImV4cCI6MTU4OTI0NzY4NywiZW1haWwiOiJiZW5yc29tbWVyQGljbG91ZC5jb20iLCJlbWFpbF92ZXJpZmllZCI6ZmFsc2UsImZpcmViYXNlIjp7ImlkZW50aXRpZXMiOnsiZW1haWwiOlsiYmVucnNvbW1lckBpY2xvdWQuY29tIl19LCJzaWduX2luX3Byb3ZpZGVyIjoicGFzc3dvcmQifX0.luzWFCR3xr7OmbAp38_qXTlEv800_NMZUBqfa_DfHc5pM9i4CRBr5en3AjzRIjJP2AYF50Z3OE4c7LvnD5VPhEMLmDJcl8xwe_q0uzlMxIIEQdUANui0eFIEK__mFbZS9QmoBwFP4mBa2diuRaZsuUW0rJXkPCzweeiIvJoeGDfGnYnz1KKH1KuDdPKb5sFcHxKCnMCnyr61rDYDEfFbOwDrZBuC94gtrEQtwqb5ruy453CJk0v1wVU8NpbgMhOUvq4AHYCRtNFAqmDDKFNYr1WJTdx3Eqmcn2segocXj-MdQzT5FZtdpxtRad8SKA1FCI03vBYNQDL8rtwFaVFt_A',
        'content-type': 'application/json',
        forwarded: 'for="81.111.170.171";proto=https',
        'function-execution-id': 'b2egqxx6o36z',
        origin: 'http://localhost:3000',
        referer: 'http://localhost:3000/sign-up',
        'sec-fetch-dest': 'empty',
        'sec-fetch-mode': 'cors',
        'sec-fetch-site': 'cross-site',
        'x-appengine-city': 'chesham',
        'x-appengine-citylatlong': '51.709401,-0.612333',
        'x-appengine-country': 'GB',
        'x-appengine-default-version-hostname': 'uc2d66f008c134574p-tp.appspot.com',
        'x-appengine-https': 'on',
        'x-appengine-region': 'eng',
        'x-appengine-request-log-id': '5eb9f0ea00ff0d575c33c56a980001737e7563326436366630303863313334353734702d7470000133646535326134613634643339346235623664653837626165353130396466393a3230000100',
        'x-appengine-user-ip': '81.111.170.171',
        'x-cloud-trace-context': '17c316a639a7d55b4e52ddc72c5ae94f/11631072639755688744',
        'x-forwarded-for': '81.111.170.171',
        'x-forwarded-proto': 'https',
        connection: 'close' },
     rawHeaders: 
      [ 'Host',
        'us-central1-universal-alert.cloudfunctions.net',
        'User-Agent',
        'Mozilla/5.0 (Macintosh
    ```

Is the origin value here guaranteed and reliable? Is there a better way to implement this?

1 个答案:

答案 0 :(得分:2)

您似乎可以发送context.rawRequest.headers.origin的值。无需发送整个对象。