问题
I am trying to deploy my nodejs application in Google App Engine. But I keep on getting 502 Bad Gateway when I run
$ gcloud app browse
This is my file structure
->project
|___node_modules
|___models
|___routes
|___index.js
|___app.yaml
|___package.json
|___package.lock.json
|___public
|___index.html
|___js
This is my app.yaml file
env: flex
runtime: nodejs
threadsafe: true
manual_scaling:
instances: 1
# Handle the main page by serving the index page.
handlers:
- url: /
static_files: public/index.html
upload: public/index.html
- url: /(.*)
static_files: public/\1
upload: public/(.*)
# Recommended file skipping declaration from the GAE tutorials
skip_files:
- ^(.*/)?app\.yaml
- ^(.*/)?app\.yml
- ^(.*/)?#.*#
- ^(.*/)?.*~
- ^(.*/)?.*\.py[co]
- ^(.*/)?.*/RCS/.*
- ^(.*/)?\..*
- ^(.*/)?tests$
- ^(.*/)?test$
- ^test/(.*/)?
- ^COPYING.LESSER
- ^README\..*
- \.gitignore
- ^\.git/.*
- \.*\.lint$
- ^fabfile\.py
- ^testrunner\.py
- ^grunt\.js
- ^node_modules/(.*/)?
Note: I am running on port 8080 and have included "start" : "node index.js" in package.json
回答1:
I found my mistake. It was in the index.js file. Previously:
const port = process.env.PORT || 8080;
app.listen(port, "localhost",()=>{
console.log("Server running at port " + port);
});
I had to replace it with:
const port = process.env.PORT || 8080;
app.listen(port, ()=>{
console.log("Server running at port " + port);
});
来源:https://stackoverflow.com/questions/56101815/502-bad-gateway-while-deploying-in-gae