【问题标题】:How to configure app.yaml file for node react project in google app engine如何在谷歌应用引擎中为节点反应项目配置 app.yaml 文件
【发布时间】:2019-06-10 04:57:50
【问题描述】:

我正在使用 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

【问题讨论】:

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


    【解决方案1】:

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

    - 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 文件中。

    【讨论】:

    • 其实我需要这个通配符处理程序,但它不起作用
    • 您可以将您的应用程序与this one 进行比较,以找出可能导致问题的任何差异。检查app.js 文件中是否有express 入口点(在其下定义了应用程序处理程序)。同样,检查package.json 文件,它应该指定application startup 和您正在使用的依赖项。
    • 这种方法对我不起作用。对我有用的是这个问题中编写的 app.yaml 处理程序(是的,问题,它已变成答案):stackoverflow.com/questions/54247953/…
    猜你喜欢
    • 1970-01-01
    • 2020-10-15
    • 1970-01-01
    • 2011-10-02
    • 1970-01-01
    • 1970-01-01
    • 2023-03-11
    • 2014-08-02
    • 2018-05-24
    相关资源
    最近更新 更多