在 Google App Engine 上部署 React 应用程序:app.yaml 路径问题

Deploy react app on Google App Engine: app.yaml problems with path

我尝试在 google 应用引擎上 运行 一个 React 应用,但是 app.yaml 配置有一些问题。如果 url 路径是 https://example.com/path. But there are also some routes like https://example.com/path/subpath,则 React 应用程序正在运行,但它不起作用。

问题是 React 应用试图获取具有以下路径的 .js 和 .css 文件:

但必须是:

结尾/路径也不起作用:https://example.com/path/

我的app.yaml:

service: react-app
runtime: nodejs12
handlers:
  - url: /static/js/(.*)
    static_files: build/static/js/
    upload: build/static/js/(.*)
  - url: /static/css/(.*)
    static_files: build/static/css/
    upload: build/static/css/(.*)
  - url: /static/media/(.*)
    static_files: build/static/media/
    upload: build/static/media/(.*)
  - url: /(.*\.(json|ico))$
    static_files: build/
    upload: build/.*\.(json|ico)$
  - url: /
    static_files: build/index.html
    upload: build/index.html
  - url: /.*
    static_files: build/index.html
    upload: build/index.html

我的文件夹结构是:

build/
- static/
-- css/
-- js/
-- media/
- index.html
app.yaml

也许有人对我有同样的问题或解决方案。 谢谢!

我发现您在部署 App Engine 应用程序时遇到问题,当您尝试获取 .js 和 .css 文件时,您的应用程序正在错误的路径中搜索它们。

official documentation 关于如何使用 NodeJS 为 App Engine 管理和提供静态文件,您可以尝试遵循文档中关于如何正确构建 app.yaml 文件的指南获取您的静态文件。

我还找到了一个 guide(虽然它使用 Python 作为运行时),它显示了一个类似的项目结构和一个关于如何构建 app.yaml 的示例。

我认为您的 app.yaml 文件获取 URL 的方式可能是问题所在,尽管子路径的整体处理程序结构也应该修改。