calling external web services from my NODEJS GAE APP

24 views
Skip to first unread message

mags Sweet

unread,
Jan 8, 2019, 8:00:49 PM1/8/19
to Google App Engine
Hi!,

I am new to NODE JS + GAE so pls forgive newbie question.

I want my app to serve up a REST call that will consolidate the results of calls to other externally hosted API's (third parties - none GAE)

I have this javascript working from my PC but when I deploy to GAE i get "502 Bad Gateway" errors. I can't find anything in the logs to help explain this error. Note my REST call is working (ie GAE is receiving the call) but is failing to make the outbound call to external web site.

Note here is sample NODE JS code that is failing:



'use strict';

 

const express = require('express');

var http = require('http');

var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;

 

const app = express();

 


// [START hello_world]



 

app.get('/test', (req, res) => {

const Http = new XMLHttpRequest();

const url='https://www.google.com';

Http.open("GET", url);

Http.send();

Http.onreadystatechange=(e)=>{

console.log(Http.responseText)

}});

 

// [END hello_world]

 

if (module === require.main) {

  // [START server]

  // Start the server

  const server = app.listen(process.env.PORT || 8080, () => {

    const port = server.address().port;

    console.log(`App listening on port ${port}`);

  });

  // [END server]

}

 

module.exports = app;

 

 

George (Cloud Platform Support)

unread,
Jan 9, 2019, 4:12:50 PM1/9/19
to Google App Engine
502 errors are generated when there was difficulty reaching a service, in your case this is likely caused by the outbound calls failing. Currently, there is no implementation of urlfetch for Node.js so you would have to use the standard HTTP library or other libraries to issue HTTP requests. 

This discussion group is oriented more towards general opinions, trends, and issues of general nature touching the app engine. For coding and programming architecture, as well as setting up proxies, you may be better served in dedicated forums such as stackoverflow, where experienced programmers are within reach and ready to help. 
Reply all
Reply to author
Forward
0 new messages