reactjs 使用Google App Engine部署存储在Cloud Storage存储桶中的React Build会返回404错误页面

llmtgqce  于 2023-04-11  发布在  React
关注(0)|答案(2)|浏览(141)

我已经将我的react build存储在云存储桶中。

应用引擎Yaml配置:

service: demo-react-app
runtime: python39

handlers:
  - url: /
    static_files: build/index.html
    upload: build/index.html

  - url: /(.*)
    static_files: build/\1
    upload: build/(.*)

部署日志:

dineshsonachalam@macbook infra_v2 % gcloud app deploy app_engine.yaml --bucket=gs://dinesh_test_bucket_2023 --version=1-0-0 --quiet

Services to deploy:

descriptor:                  [/Users/dineshsonachalam/Desktop/react-app/app_engine.yaml]
source:                      [/Users/dineshsonachalam/Desktop/react-app]
target project:              [iac-v4]
target service:              [demo-react-app]
target version:              [1-0-0]
target url:                  [https://demo-react-app-dot-iac-v4.nw.r.appspot.com]
target service account:      [App Engine default service account]

Beginning deployment of service [demo-react-app]...
╔════════════════════════════════════════════════════════════╗
╠═ Uploading 3 files to Google Cloud Storage                ═╣
╚════════════════════════════════════════════════════════════╝
File upload done.
Updating service [demo-react-app]...done.                                                                         
Setting traffic split for service [demo-react-app]...done.                                                        
Deployed service [demo-react-app] to [https://demo-react-app-dot-iac-v4.nw.r.appspot.com]

You can stream logs from the command line by running:
  $ gcloud app logs tail -s demo-react-app

To view your application in the web browser run:
  $ gcloud app browse -s demo-react-app

部署后我的应用程序引擎返回404页面未找到错误页面。

令人惊讶的是,如果我的react构建存储在我的本地目录中,而不是云存储桶中,react应用程序渲染可以正常工作。

部署日志:

dineshsonachalam@macbook infra_v2 % ls -lrt
total 16
-rw-r--r--   1 dineshsonachalam  staff  193  9 Apr 21:22 app_engine.yaml
-rw-r--r--   1 dineshsonachalam  staff  140  9 Apr 21:22 README.md
drwxr-xr-x@ 10 dineshsonachalam  staff  320  9 Apr 21:28 build
dineshsonachalam@macbook infra_v2 % gcloud app deploy app_engine.yaml --bucket=gs://dinesh_test_bucket_2023 --version=1-0-2

Services to deploy:

descriptor:                  [/Users/dineshsonachalam/Desktop/react-app/app_engine.yaml]
source:                      [/Users/dineshsonachalam/Desktop/react-app]
target project:              [iac-v4]
target service:              [demo-react-app]
target version:              [1-0-2]
target url:                  [https://demo-react-app-dot-iac-v4.nw.r.appspot.com]
target service account:      [App Engine default service account]

Do you want to continue (Y/n)?  y

Beginning deployment of service [demo-react-app]...
╔════════════════════════════════════════════════════════════╗
╠═ Uploading 15 files to Google Cloud Storage               ═╣
╚════════════════════════════════════════════════════════════╝
                                                                            
File upload done.
Updating service [demo-react-app]...done.                                                                         
Setting traffic split for service [demo-react-app]...done.                                                        
Deployed service [demo-react-app] to [https://demo-react-app-dot-iac-v4.nw.r.appspot.com]

You can stream logs from the command line by running:
  $ gcloud app logs tail -s demo-react-app

To view your application in the web browser run:
  $ gcloud app browse -s demo-react-app
dineshsonachalam@macbook infra_v2 %

你认为应用引擎桶选项或应用引擎处理程序有问题吗?

yfjy0ee7

yfjy0ee71#

HTTP 404错误主要是目录/文件结构问题,这意味着您的处理程序正在查找的文件不存在。或不在正确的目录中。在您的构建目录中必须有一个index.html,该文件必须位于app.yaml部署的根目录中。因此,请检查位于正确目录中的index.html文件。请参考此document1 &document2,了解有关文件结构要求的更多信息。
您还可以验证云存储桶中的文件是否可访问,并尝试将应用部署到其他云存储桶,看看问题是否与存储桶配置无关。
您也可以查看类似的stackoverflow链接以供参考。

zz2j4svz

zz2j4svz2#

gcloud app deploy的--bucket标志只用于暂存构建的文件。它不是一种识别静态文件存储的方法。此外,您不能使用App Engine静态文件处理程序指向GCS存储桶,只能指向实际包含在部署中的文件。
查看此文档,了解如何提供静态文件的不同选项。

相关问题