Firebase cloud function http request to another firebase cloud function

Viewed 1407

I have a main firebase cloud function with main functionalities. But I need to create another one more specific that uses the functionalities on the main cloud function. Can I request a http Post or Get from one firebase cloud function to another firebase cloud function with a free account?

I tried to make it but I get the 'ENOTFOUND' message, I want to know if is something wrong with my code or it is just a limitation of the free account.

index.js
'use strict';
const functions = require('firebase-functions');

const express = require('express');
const app = express();

app.post('/test', function(req, res) {
    var request = require('request')

    var options = {
      method: 'post',
      body: req.body, // re-send the incoming body to the main cloud function
      json: true, 
      url: '<main cloud url>',
      headers: req.headers // re-send the incoming headers the main cloud function
    }
    request(options, function (err, response, body) {
      if (err || response.statusCode != 200) {
        res.status(400).send(err); //re-send the received error to the client
        return
      }
      res.send(body); //re-send the received response to the client
    });
});

exports.checkAtivation = functions.https.onRequest(app);
1 Answers
Related