502 Bad Gateway while deploying in GAE

笑着哭i 提交于 2021-01-29 09:23:21

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!