Make HTTPS call within Firebase Function











up vote
0
down vote

favorite












I am trying to make a call within a firebase function to a locally managed server. I am not super familiar with node as a development environment so I am not sure what is the issue.



const functions = require('firebase-functions');
const https = require('http');
exports.testPost = functions.https.onRequest((req, res) => {
var options = {
host: 'localdevserver.edu',
port: 80,
path: '/my/endpoint'
};
let data = '';

http.get(options, function(resp){
resp.on('data', function(chunk){
//do something with chunk
data += chunk;
resp.on('end', console.log("dones"));
});
}).on("error", function(e){
console.log("Got error: " + e.message);
});
});


When I look in the Firebase Functions Log, it says either timeout or no reject defined.










share|improve this question


















  • 1




    Start off with returning a string to test that it's actually working. Note that you can deploy functions locally with firebase serve --only functions (Quicker to test)
    – Philip
    Nov 10 at 21:27

















up vote
0
down vote

favorite












I am trying to make a call within a firebase function to a locally managed server. I am not super familiar with node as a development environment so I am not sure what is the issue.



const functions = require('firebase-functions');
const https = require('http');
exports.testPost = functions.https.onRequest((req, res) => {
var options = {
host: 'localdevserver.edu',
port: 80,
path: '/my/endpoint'
};
let data = '';

http.get(options, function(resp){
resp.on('data', function(chunk){
//do something with chunk
data += chunk;
resp.on('end', console.log("dones"));
});
}).on("error", function(e){
console.log("Got error: " + e.message);
});
});


When I look in the Firebase Functions Log, it says either timeout or no reject defined.










share|improve this question


















  • 1




    Start off with returning a string to test that it's actually working. Note that you can deploy functions locally with firebase serve --only functions (Quicker to test)
    – Philip
    Nov 10 at 21:27















up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am trying to make a call within a firebase function to a locally managed server. I am not super familiar with node as a development environment so I am not sure what is the issue.



const functions = require('firebase-functions');
const https = require('http');
exports.testPost = functions.https.onRequest((req, res) => {
var options = {
host: 'localdevserver.edu',
port: 80,
path: '/my/endpoint'
};
let data = '';

http.get(options, function(resp){
resp.on('data', function(chunk){
//do something with chunk
data += chunk;
resp.on('end', console.log("dones"));
});
}).on("error", function(e){
console.log("Got error: " + e.message);
});
});


When I look in the Firebase Functions Log, it says either timeout or no reject defined.










share|improve this question













I am trying to make a call within a firebase function to a locally managed server. I am not super familiar with node as a development environment so I am not sure what is the issue.



const functions = require('firebase-functions');
const https = require('http');
exports.testPost = functions.https.onRequest((req, res) => {
var options = {
host: 'localdevserver.edu',
port: 80,
path: '/my/endpoint'
};
let data = '';

http.get(options, function(resp){
resp.on('data', function(chunk){
//do something with chunk
data += chunk;
resp.on('end', console.log("dones"));
});
}).on("error", function(e){
console.log("Got error: " + e.message);
});
});


When I look in the Firebase Functions Log, it says either timeout or no reject defined.







firebase google-cloud-functions






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 10 at 17:31









Lloyd

81641632




81641632








  • 1




    Start off with returning a string to test that it's actually working. Note that you can deploy functions locally with firebase serve --only functions (Quicker to test)
    – Philip
    Nov 10 at 21:27
















  • 1




    Start off with returning a string to test that it's actually working. Note that you can deploy functions locally with firebase serve --only functions (Quicker to test)
    – Philip
    Nov 10 at 21:27










1




1




Start off with returning a string to test that it's actually working. Note that you can deploy functions locally with firebase serve --only functions (Quicker to test)
– Philip
Nov 10 at 21:27






Start off with returning a string to test that it's actually working. Note that you can deploy functions locally with firebase serve --only functions (Quicker to test)
– Philip
Nov 10 at 21:27














2 Answers
2






active

oldest

votes

















up vote
2
down vote



accepted










With HTTP type functions, you need to send a response to the client in order to terminate the function. Otherwise it will time out.



res.send("OK");


Please read the documentation for more details.






share|improve this answer





















  • This was indeed part of my problem. I had will add my final solution to your answer for reference.
    – Lloyd
    Nov 12 at 15:20






  • 1




    I don't think the code in your proposed edit is going to work the way you exepct because you're sending a response before the other HTTP transaction is complete. That runs the risk of terminating the function before the async request is complete.
    – Doug Stevenson
    Nov 12 at 16:18


















up vote
0
down vote













You can use SYNC-REQUEST




npm install sync-request




var request = require('sync-request');
var res = request('GET', 'http://google.com');
console.log(res.body.toString('utf-8'));


the function would be something like this:



exports.testPost = functions.https.onRequest((req, res) => {

var request = require('sync-request');
var res = request('GET', 'http://google.com');
var res = res.body.toString('utf-8');

resp.on(res, console.log("dones"));
});





share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241602%2fmake-https-call-within-firebase-function%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote



    accepted










    With HTTP type functions, you need to send a response to the client in order to terminate the function. Otherwise it will time out.



    res.send("OK");


    Please read the documentation for more details.






    share|improve this answer





















    • This was indeed part of my problem. I had will add my final solution to your answer for reference.
      – Lloyd
      Nov 12 at 15:20






    • 1




      I don't think the code in your proposed edit is going to work the way you exepct because you're sending a response before the other HTTP transaction is complete. That runs the risk of terminating the function before the async request is complete.
      – Doug Stevenson
      Nov 12 at 16:18















    up vote
    2
    down vote



    accepted










    With HTTP type functions, you need to send a response to the client in order to terminate the function. Otherwise it will time out.



    res.send("OK");


    Please read the documentation for more details.






    share|improve this answer





















    • This was indeed part of my problem. I had will add my final solution to your answer for reference.
      – Lloyd
      Nov 12 at 15:20






    • 1




      I don't think the code in your proposed edit is going to work the way you exepct because you're sending a response before the other HTTP transaction is complete. That runs the risk of terminating the function before the async request is complete.
      – Doug Stevenson
      Nov 12 at 16:18













    up vote
    2
    down vote



    accepted







    up vote
    2
    down vote



    accepted






    With HTTP type functions, you need to send a response to the client in order to terminate the function. Otherwise it will time out.



    res.send("OK");


    Please read the documentation for more details.






    share|improve this answer












    With HTTP type functions, you need to send a response to the client in order to terminate the function. Otherwise it will time out.



    res.send("OK");


    Please read the documentation for more details.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 10 at 22:03









    Doug Stevenson

    64.1k77695




    64.1k77695












    • This was indeed part of my problem. I had will add my final solution to your answer for reference.
      – Lloyd
      Nov 12 at 15:20






    • 1




      I don't think the code in your proposed edit is going to work the way you exepct because you're sending a response before the other HTTP transaction is complete. That runs the risk of terminating the function before the async request is complete.
      – Doug Stevenson
      Nov 12 at 16:18


















    • This was indeed part of my problem. I had will add my final solution to your answer for reference.
      – Lloyd
      Nov 12 at 15:20






    • 1




      I don't think the code in your proposed edit is going to work the way you exepct because you're sending a response before the other HTTP transaction is complete. That runs the risk of terminating the function before the async request is complete.
      – Doug Stevenson
      Nov 12 at 16:18
















    This was indeed part of my problem. I had will add my final solution to your answer for reference.
    – Lloyd
    Nov 12 at 15:20




    This was indeed part of my problem. I had will add my final solution to your answer for reference.
    – Lloyd
    Nov 12 at 15:20




    1




    1




    I don't think the code in your proposed edit is going to work the way you exepct because you're sending a response before the other HTTP transaction is complete. That runs the risk of terminating the function before the async request is complete.
    – Doug Stevenson
    Nov 12 at 16:18




    I don't think the code in your proposed edit is going to work the way you exepct because you're sending a response before the other HTTP transaction is complete. That runs the risk of terminating the function before the async request is complete.
    – Doug Stevenson
    Nov 12 at 16:18












    up vote
    0
    down vote













    You can use SYNC-REQUEST




    npm install sync-request




    var request = require('sync-request');
    var res = request('GET', 'http://google.com');
    console.log(res.body.toString('utf-8'));


    the function would be something like this:



    exports.testPost = functions.https.onRequest((req, res) => {

    var request = require('sync-request');
    var res = request('GET', 'http://google.com');
    var res = res.body.toString('utf-8');

    resp.on(res, console.log("dones"));
    });





    share|improve this answer

























      up vote
      0
      down vote













      You can use SYNC-REQUEST




      npm install sync-request




      var request = require('sync-request');
      var res = request('GET', 'http://google.com');
      console.log(res.body.toString('utf-8'));


      the function would be something like this:



      exports.testPost = functions.https.onRequest((req, res) => {

      var request = require('sync-request');
      var res = request('GET', 'http://google.com');
      var res = res.body.toString('utf-8');

      resp.on(res, console.log("dones"));
      });





      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        You can use SYNC-REQUEST




        npm install sync-request




        var request = require('sync-request');
        var res = request('GET', 'http://google.com');
        console.log(res.body.toString('utf-8'));


        the function would be something like this:



        exports.testPost = functions.https.onRequest((req, res) => {

        var request = require('sync-request');
        var res = request('GET', 'http://google.com');
        var res = res.body.toString('utf-8');

        resp.on(res, console.log("dones"));
        });





        share|improve this answer












        You can use SYNC-REQUEST




        npm install sync-request




        var request = require('sync-request');
        var res = request('GET', 'http://google.com');
        console.log(res.body.toString('utf-8'));


        the function would be something like this:



        exports.testPost = functions.https.onRequest((req, res) => {

        var request = require('sync-request');
        var res = request('GET', 'http://google.com');
        var res = res.body.toString('utf-8');

        resp.on(res, console.log("dones"));
        });






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 11 at 15:03









        Mike Brian Olivera

        3651513




        3651513






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241602%2fmake-https-call-within-firebase-function%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            List item for chat from Array inside array React Native

            Thiostrepton

            Caerphilly