【问题标题】:Angular page shows 404 when refreshed - error only occurs on Google CloudAngular 页面在刷新时显示 404 - 错误仅发生在 Google Cloud 上
【发布时间】:2021-11-26 04:27:20
【问题描述】:

我正在为 GCP 开发一个 Angular 项目(使用 App Engine + Storage,还没有 Docker 的东西),我在刷新其中一个页面时遇到了问题。

这是 index.html 上的搜索引擎,可在“页面”domain.com/results 上显示结果。我可以进入结果页面;通过浏览器返回;通过我创建的界面返回……没问题。刷新结果页面时出现问题:

这对我来说听起来很奇怪,因为在本地和 AWS 上,同一个项目运行顺利。只有当我使用 GCP 时它才会中断 - 这是项目的官方云。

这是我的 app.yaml 文件:

runtime: python27
    api_version: 1
    threadsafe: true

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

    - url: /
      static_dir: skote

还有我在 Storage 上的文件夹结构:

bucket
├─ skote/
│  ├─ assets/
│  ├─ index.html
│  ├─ favicon.ico
│  ├─ lot-of-files-in-css-js
├─ app.yaml

我等待帮助。谢谢!

【问题讨论】:

    标签: angular google-app-engine google-cloud-platform google-cloud-storage http-status-code-404


    【解决方案1】:

    您的问题与question 类似。如果您的应用程序的路由运行良好,请尝试向您的 app.yaml in handlers 元素添加一个配置,以允许其他静态文件为您的应用程序提供服务。例如:

    app.yaml

    runtime: python27
    api_version: 1
    threadsafe: true
    
    handlers:
     # allow any file with an extension.
    - url: /(.*\.(.+))$
      static_files: /\1
      upload: skote/(.*\.(.+))$
    
    - url: /
      static_files: skote/index.html
      upload: skote/index.html
    
    - url: /
      static_dir: skote  
    

    【讨论】:

    • 感谢您的帮助。我看过这个话题,甚至测试过这个实现,但不幸的是它不起作用:出现同样的错误。
    • 我尝试了简单的应用程序,没有问题。也许您可以提供示例应用程序的副本,或者我们如何重现您的问题?您是否从 Cloud Storage 存储分区提供静态文件?
    • 我们以静态格式提供应用程序,是的。考虑到紧迫性,我最终通过改变部署方法解决了这个问题:我将它部署到 Firebase,它就像一个魅力。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-07-21
    • 1970-01-01
    • 1970-01-01
    • 2019-11-01
    • 2018-11-27
    • 2019-04-30
    • 1970-01-01
    相关资源
    最近更新 更多