node.js - 如何在谷歌应用程序引擎中为 Node react 项目配置app.yaml文件

标签 node.js reactjs google-app-engine web-deployment devops

我正在使用react js和nodejs开发一个应用程序。当我在本地计算机中运行该应用程序时,它可以正常工作作为示例

localhost:3000/AboutUs
localhost:3000

当我刷新上述 URL 时,它会显示正确的网页。我在 Google App Engine 中部署此应用程序,当我刷新下面的页面时,它显示找不到所请求的 URL。谁能告诉我这是什么原因吗?

www.mydomain.com/AboutUs

app.yaml代码如下

runtime: nodejs8
handlers:
- url: /api/.*
# secure: always
# redirect_http_response_code: 301
script: auto
- url: /
static_files: build/index.html
upload: build/index.html

最佳答案

这是因为您没有定义的处理程序来定向您的 /AboutUs URL。您可以在处理程序下添加:

- url: /AboutUs
  script: auto

或者在url列表末尾添加通配符处理程序,例如:

runtime: nodejs8
handlers:
- url: /api/.*
# secure: always
# redirect_http_response_code: 301
  script: auto
- url: /
  static_files: build/index.html
  upload: build/index.html
- url: /.*
  script: auto

将通配符处理程序 /.* 保留在末尾非常重要,否则所有 URL 都将位于其下,并且它不会使用其他 url 处理程序。

此外,网址下的 scriptstatic_filesupload 标记中缺少两个空格,我不知道是否是因为将 app.yaml 内容复制到您的答案时的格式所致,但无论如何,indentation is important在 YAML 文件中。

关于node.js - 如何在谷歌应用程序引擎中为 Node react 项目配置app.yaml文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54211424/

相关文章:

javascript - 在 Reactjs 样式 block 中添加两个变量

javascript - 删除表单内字符串两端的空格 - React

java - Google Cloud Storage API 无法在 App Engine 上获取应用程序默认凭据以查找 Compute Engine 错误

javascript - 部署 Node JS 后,图像(PNG、JPG)不会显示在 Heroku 应用程序上

ios - 原生脚本 | Firebase 通知不起作用

javascript - 如何在 Node 中使用 require 和 module.exports 而不重复?

python - 将 py2neo v3 与谷歌应用引擎一起使用

javascript - Mathjax 和 JadeJS 的集成

javascript - 如何将 "img"对象传递给 ReactJS JSX 中的 onload 事件处理程序?

google-app-engine - 上传 100 万张图片到 BlobStore