Search code examples
node.jshttpgoogle-app-enginerequestwordpress-rest-api

WordPress.com API working locally but not on App Engine


Called the Wordpress API via the Request module. Running my server locally the call returns correctly. Using postman the url returns correctly.

However when I deploy my app to Google App Engine the response returns undefined for the response in the Request call.

app.get('/api/test', (req, res) => {
  console.log("testing"); 
  // res.send({ express: 'Hello From testing' });
request('https://public-api.wordpress.com/rest/v1/sites/testblog.wordpress.com/posts', { json: true }, (err, response, body) => {
  console.log(response.statusCode)
  console.log(body); 
if (err) { return console.log(err); }
  console.log(body);
  res.send({ express: body.ID })
});
});

Solution

  • When App Engine is making an outbound HTTPS request (fetching URL) it checks for the certificate of the requested url. If for any reason the certificate is not valid App Engine rejects the request. As per the documentation, to disable host certificate validation set the value of verify_peer to false.

    You should also read about the limits and quotas for URL fetch.