使用 Google 云 SDK shell 在 GAE 中部署

Deploying in GAE using Google cloud SDK shell

我正在尝试在 Google App Engine 上部署我的 Nodejs 应用程序。我正在使用 Google Cloud SDK Shell 来 运行 宁 gcloud 命令。

首先我运行 gcloud init:

C:\Users\<UserName>\AppData\Local\Google\Cloud SDK>gcloud init

之后我选择了要使用的云项目。 然后我转到我的项目目录和 运行 部署命令:

C:\Users\<UserName>\Documents\Hosting\api>gcloud app deploy

但是当我 运行 gcloud app browse 时,我收到 502 Bad Gateway。 我的项目结构是:

->api
  |___node_modules
  |___models
  |___routes
  |___index.js
  |___app.yaml
  |___package.json
  |___package.lock.json
->public
  |___index.html
  |___js
  1. 我应该在哪里 运行 gcloud app deploy 命令?
  2. 我是否应该更改项目结构(当我 运行 从 /[=41 执行命令时,google-sdk 将如何知道我的前端文件在 /public 文件夹中=])

注意:我已经在端口 8080 上 运行ning 并且在 package.json 文件中包含了 "start" 脚本。

我必须 re-structure 我的项目:

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

此外,我还必须对 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);
});