在GAE中部署时出现502错误的网关

时间:2019-05-12 17:39:08

标签: node.js google-app-engine deployment web-hosting app.yaml

我正在尝试在Google App Engine中部署我的nodejs应用程序。 但是当我运行

时,我会不断遇到 502错误的网关
$ gcloud app browse

这是我的文件结构

->project
  |___node_modules
  |___models
  |___routes
  |___index.js
  |___app.yaml
  |___package.json
  |___package.lock.json
  |___public
      |___index.html
      |___js 

这是我的app.yaml文件

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/(.*/)?

注意:我正在端口8080上运行,并在package.json中包含了“ start”:“ node index.js”

1 个答案:

答案 0 :(得分:0)

我发现了我的错误。它在index.js文件中。 以前:

const port = process.env.PORT || 8080;
app.listen(port, "localhost",()=>{
    console.log("Server running at port " + port);
});

我必须将其替换为:

const port = process.env.PORT || 8080;
app.listen(port, ()=>{
    console.log("Server running at port " + port);
});
相关问题