簡體   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