Reputation: 361
I deployed an App to google's App Engine service, a simple Express.js server that served dynamic pages rendered with Handlebars.js. Everything was fine for some hours (It was serving the pages) and suddenly it started answering with this message:
502 Error: Server Error The server encountered a temporary error and could not complete your request. Please try again in 30 seconds.
I tried all the following to fix it:
Even the new project answers with 502.
My thought: I think that Google´s proxy is not sending the request to the app, since it is Actualy listening, but it does not log the requests.
Here is the code:
App.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}`);
});
package.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"
}
}
app.yaml
runtime: nodejs
env: flex
automatic_scaling:
min_num_instances: 1
resources:
cpu: 1
memory_gb: 1
disk_size_gb: 10
I am out of options... Any thoughts on what might be the issue?
The weird thing is that it was running smoothly for some hours before this started, now it only answers with 502.
Upvotes: 2
Views: 1181
Reputation: 67
It is necessary to declare a route at the base, returning http status 200.
Be careful with the order of declaring the routes. So as not to risk overwriting.
Example:
app.get('/', function (req, res) {
res.status(200).send('Health Check');
});
Upvotes: 1