我正在使用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 处理程序。
此外,网址下的 script
、static_files
和 upload
标记中缺少两个空格,我不知道是否是因为将 app.yaml
内容复制到您的答案时的格式所致,但无论如何,indentation is important在 YAML 文件中。
关于node.js - 如何在谷歌应用程序引擎中为 Node react 项目配置app.yaml文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54211424/