Google Cloud Storage 上的网站配置没有错误页面

问题描述 投票:0回答:3

我有一个单页应用程序,我正在(尝试)在 Google Cloud Storage 上托管。

应用程序位于index.html,应用程序使用Angular的html5Mode处理路由。 (例如:像 example.com/this 和 example.com/ 这样的路由由 index.html 中的 js 应用程序处理)

使用 Google Cloud Storage 的网站配置,这一切都很好,除了直接访问的路由(“example.com/this”)将出现 404,因为它们显然没有映射到文件。

我已将 404 页面设置为索引页,但为了在 html5Mode 中运行单页应用程序,我真正需要的是此类路由(“example.com/this”)不会返回 404 标头 - 它们会只需由 index.html 处理并返回成功标头 (200)。

这可能吗?

html angularjs single-page-application google-cloud-storage pushstate
3个回答
5
投票

从网站配置中将 index.html 设置为您的 404 页面 似乎现在可以解决问题。


2
投票

不幸的是,这实际上是不可能的。 Google Cloud Storage 的网络映射非常简单,您无法根据模式等创建任意规则。

您可能需要考虑禁用 html5mode 或强制使用 html5mode 进行 hashbang。有关该选项的更多信息,请参阅此答案


0
投票

推荐的方法是在云存储桶前面放置一个全局外部负载均衡器。在负载均衡器中,您可以创建一个路由规则,它将每个请求重写到您的

index.html

defaultService: projects/xxxx/global/backendBuckets/spa
name: path-matcher-1
routeRules:
- matchRules:
  - pathTemplateMatch: /**
  priority: 10
  service: projects/xxxx/global/backendBuckets/spa
  routeAction:
    urlRewrite:
      pathTemplateRewrite: /index.html
© www.soinside.com 2019 - 2024. All rights reserved.