-
Notifications
You must be signed in to change notification settings - Fork 216
Description
Version info
firebase-functions: 0.5.7
firebase-tools: 3.9.1
firebase-admin: 4.2.1
Test case
Hello. Thank you for read me.
I have the following case:
I'm trying to do an http GET request from firebase function, this is my code:
(I'm using a test API from "jsonplaceholder" just to get Random Data and then test my real functionality.)
const functions = require('firebase-functions');
const http = require('http');
exports.myFunction= functions.https.onRequest((request, response) => {
var options = {
host: 'jsonplaceholder.typicode.com',
path: '/posts/1',
};
var req = http.get(options, function(res) {
console.log('STATUS: ' + res.statusCode);
console.log('HEADERS: ' + JSON.stringify(res.headers));
// Buffer the body entirely for processing as a whole.
var bodyChunks = [];
res.on('data', function(chunk) {
bodyChunks.push(chunk);
}).on('end', function() {
var body = Buffer.concat(bodyChunks);
console.log('BODY: ' + body);
})
});
req.on('error', function(e) {
console.log('ERROR: ' + e.message);
});
response.send("Hello from Firebase!"); //just to send something in response.
}
Steps to reproduce
When I test that function in my LOCAL environment on a test case using node index.js
, everything works just fine!
Were you able to successfully deploy your functions?
When I do firebase deploy
everything deploys just fine, the function is uploaded to my function dashboard.
Expected behavior
The expected behavior is that the log printing the body returns something like:
STATUS: 200
BODY: {
"userId": 1,
"id": 1,
"title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
"body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae
ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
}
Actual behavior
The actual behavior is this:
ERROR: getaddrinfo ENOTFOUND https://jsonplaceholder.typicode.com https://jsonplaceholder.typicode.com:443
Thats what's happening when I trigger the function on firebase, but in my local environment everything work ust fine.. is that a bug?
Thank you very much!