I'm serving an application via AWS Elastic Beanstalk. localhost
and ngrok
serve the webpage and additional api calls as expected. When uploaded to AWS-ELB
a 504 error
is the response for any additional api calls after the webpage is served.
The application serves the base index.html file via:
BASIC SETUP AND SERVING INDEX.HTML
app.use(bodyParser.urlencoded({ extended: true }))
app.use(bodyParser.json())
app.all('/', ensureSecure)
function ensureSecure(req, res, next){
if(req.headers['x-forwarded-proto'] === 'https'){
// OK, continue
return next()
};
res.redirect('https://' + req.headers.host)
}
app.use(express.static(__dirname + '/../web'), () => {}) // SERVE THE WEBPAGE
var port = process.env.PORT || 443
var router = express.Router()
router.use(function(req, res, next) {
console.log('here')
res.setHeader("Access-Control-Allow-Methods", "POST, PUT, OPTIONS, DELETE, GET");
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next(); // make sure we go to the next routes and don't stop here
});
It then has additional routes below it:
SUBSEQUENT API CALL
app.get('/user/:type', function(req, res) {
res.setHeader("Access-Control-Allow-Methods", "POST, PUT, OPTIONS, DELETE, GET");
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
var dbparams = {};
dbparams.TableName = 'FFUserTable';
dbparams.KeyConditionExpression = 'uid = :uid'
dbparams.ExpressionAttributeValues = {':uid':req.query.uid};
ddb_calls.awsDynamoQuery(dbparams, function(data){
res.json(data);
})
})
The index page serves and renders just fine. But any of the routes below it return a 504 gateway error when the page makes calls to them. The strange thing is that this only happens when deployed to AWS-ELB. Everything works as expected when using localhost
or when using ngrok
. Even if I take out the https
redirect I get the same issue.
AWS-ELB ssl is setup and routed correctly via AWS-Route53.
index.html
from the same server. – Phil Andrewsddb_calls.awsDynamoQuery
might be causing the timeout. – robertklep