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.
add a comment |
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.
1
Start off with returning a string to test that it's actually working. Note that you can deploy functions locally withfirebase serve --only functions(Quicker to test)
– Philip
Nov 10 at 21:27
add a comment |
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.
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.
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 withfirebase serve --only functions(Quicker to test)
– Philip
Nov 10 at 21:27
add a comment |
1
Start off with returning a string to test that it's actually working. Note that you can deploy functions locally withfirebase 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
add a comment |
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.
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
add a comment |
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"));
});
add a comment |
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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"));
});
add a comment |
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"));
});
add a comment |
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"));
});
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"));
});
answered Nov 11 at 15:03
Mike Brian Olivera
3651513
3651513
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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