【问题标题】:Google app engine: 502 Bad Gateway only on POST requestsGoogle 应用引擎:502 Bad Gateway 仅在 POST 请求上
【发布时间】:2016-09-28 16:49:57
【问题描述】:

所以我在 GAE 上部署了一个 nodeJS 脚本,每当我点击 POST 端点时,我都会收到 502 Bad Gateway 错误。端点是一个简单的服务,它使用 phantomJS 抓取页面的屏幕截图并返回一个 JSON,其中包含图像的 base64 表示。

对此端点执行 GET 可以正常工作并返回正常的 200 响应,但是一旦我尝试 POST 请求,我就会得到:502 Bad Gateway

这是我的 app.yaml

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

我的 app.js 脚本:

'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;

注意事项: 代码适用于我的本地环境。

【问题讨论】:

  • 代码是否可以在您的本地开发环境中运行?
  • @VikramTiwari 是的,它在我的本地环境中完美运行。
  • @HarrisRobinKalash 你解决了吗?我也面临同样的问题..
  • @DanielGolub 不幸的是,没有,我已经将它放在 GAE 上,只是把它放在刚刚工作的 heroku 上。

标签: node.js google-app-engine


【解决方案1】:

看看here:

阅读日志有助于我了解导致端点问题的原因。即

“gcloud 应用日志读取”

【讨论】:

    猜你喜欢
    • 2018-04-14
    • 2013-08-04
    • 2019-12-17
    • 2014-03-05
    • 2015-08-27
    • 2016-11-23
    • 2013-09-05
    • 1970-01-01
    • 2020-05-15
    相关资源
    最近更新 更多