Use firebase cloud function to send POST request to non-google server

前端 未结 5 824
迷失自我
迷失自我 2020-11-27 03:52

I was wondering if its possible to use a firebase cloud function to send a post request to a non-google server (from what I can find I need to be on the blaze plan in order

5条回答
  •  北荒
    北荒 (楼主)
    2020-11-27 04:42

    For those of you who want to post with a JSON body this is how you can do it. (I know I needed this a while ago)

    export function postWithBodyToExternalUrl(url: string, bdy: any): Promise {
    
      const request = require('request');
    
      const options = {
        url: url,
        json: true
      };
      return new Promise(function (resolve, reject) {
        request(options, function (err, resp) {
          if (err) {
            console.log(err);
            reject({ err: err });
          }
          resolve(bdy);
        });
      });
    }
    

提交回复
热议问题