繁体   English   中英

Google App Engine 502 错误:服务器错误 Node.js

[英]Google App Engine 502 Error: Server Error Node.js

我将一个应用程序部署到 google 的 App Engine 服务,这是一个简单的 Express.js 服务器,用于提供使用 Handlebars.js 呈现的动态页面。 几个小时内一切都很好(它正在为页面提供服务),突然它开始回答以下消息:

502 错误:服务器错误 服务器遇到临时错误,无法完成您的请求。 请在 30 秒后重试。

我尝试了以下所有方法来修复它:

  • 停止/重启服务(从控制台)
  • 重新部署(从 cmd 使用命令: “gcloud app deploy”
  • 读取日志(从 cmd 使用: “gcloud app logs read”
    • 注意:这表明服务器当前正在侦听 PORT 8080
  • 禁用/启用 App Engine Api(从控制台)
  • 将代码重新构建为简单的“Hello world”响应并重新部署
  • 完全删除项目并在新项目中重新部署

甚至新项目的答案也是 502。

我的想法:我认为 Google 的代理没有将请求发送到应用程序,因为它实际上在监听,但它没有记录请求。

这是代码:

应用程序.js:

    'use strict';

const express = require('express');
const hbs = require('hbs');
const axios = require('axios');
const XLSX = require('xlsx');
const http = require('http');



const port = process.env.PORT || 8080;
const env = process.env.NODE_ENV || 'development';


let app = express();

let urls = {
  url1: **Some url**,
  url2: '**Some url2**'
};


app.set('view engine', 'hbs');

app.use(express.static('public'));    


app.get('/page1', async (req, res)=>{
  console.log('Page 1');
  try{
    let products = await getExcel(urls.url1);
    res.render('page1.hbs', {
      products: products,
    });
  }catch(err){
    console.log(err);
    res.status(500).send('Oops! found an Error.')
  }
});

app.get('/page2', async (req, res)=>{
    console.log('Page 2');
    try{
      let products = await getExcel(urls.url2);
      res.render('page2.hbs', {
        products: products,
      });
    }catch(err){
      console.log(err);
      res.status(500).send('Oops! found an Error.')
    }
 });

app.get('/', (req,res)=>{
  console.log('Home');
  res.render('smx-home.hbs',{});
});


const getExcel = async (url) =>{
**DO SOME STUFF HERE THAT RETURNS AN OBJECT OR AN ERROR** 
}    


app.listen(port, ()=>{
  console.log(`${env} Server listening on port ${port}`);
});

包.json:

{
  "name": "suplementos",
  "version": "1.0.0",
  "description": "Suplementos Cajeme y SuplementosMX",
  "main": "app.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node app.js"
  },
  "author": "Wake",
  "license": "ISC",
  "dependencies": {
    "axios": "^0.18.0",
    "express": "^4.16.3",
    "hbs": "^4.0.1",
    "xlsx": "^0.12.13"
  }
}

应用程序.yaml

runtime: nodejs
env: flex

automatic_scaling:
  min_num_instances: 1

resources:
  cpu: 1
  memory_gb: 1
  disk_size_gb: 10

我别无选择......对可能是什么问题的任何想法?

奇怪的是,它在开始之前运行了几个小时,现在它只用 502 回答。

需要在base声明路由,返回http状态200。

注意声明路由的顺序。 以免冒覆盖的风险。

例子:

    app.get('/', function (req, res) {
      res.status(200).send('Health Check');
    });  

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM