Google app engine: 502 Bad Gateway only on POST requests
<p>So I deployed a nodeJS script on GAE and whenever I hit a POST endpoint I get a 502 Bad Gateway error. The endpoint is a simple service that grabs a screenshot of a page using phantomJS and returns a JSON that contains the base64 representation of the image in it. </p>

<p>Doing a GET to this endpoint works fine and returns a healthy 200 response, however as soon as I try a POST request I get: <strong>502 Bad Gateway</strong></p>

<p>Here is my <strong>app.yaml</strong>:</p>

<pre><code>service: pdf-service

# [START runtime]
runtime: nodejs
vm: true
# [END runtime]

threadsafe: yes

# Temporary setting to keep gcloud from uploading node_modules
skip_files:
 - ^node_modules$

handlers:
- url: (.*)/
  script: app.js
  secure: always
</code></pre>

<p>My <strong>app.js</strong> script:</p>

<pre><code>'use strict';

var express = require('express');
var app = express();
var cors = require('cors');
var bodyParser = require('body-parser')
var phantom = require('./phantom');

app.use(cors());
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }))

var tmpURL = 'https://www.google.com';
// [START hello_world]
// Say hello!
app.post('/', function(req, res) {
    console.log('requrl', req.body);
    phantom.takeScreenShot(tmpURL, res);
});

app.get('/', function(req, res) {
  res.status(200).send({'greetings': 'Hello World'});
});
// [END hello_world]

if (module === require.main) {
    // [START server]
    // Start the server
    var server = app.listen(process.env.PORT || 8080, function() {
        var host = server.address().address;
        var port = server.address().port;

        console.log('App listening at http://%s:%s', host, port);
    });
    // [END server]
}

module.exports = app;
</code></pre>

<p>Notes:
<strong>The code works on my local environment.</strong></p>