在 Azure Blob 存储上使用静态网站选项托管 SPA(干净的 URL 和深层链接) [英] Hosting SPA with Static Website option on Azure Blob Storage (clean URLs and Deep links)

查看:17
本文介绍了在 Azure Blob 存储上使用静态网站选项托管 SPA(干净的 URL 和深层链接)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已按照 Microsoft 文档中的建议,使用 $web 容器成功地在 Azure Blob 存储上建立了一个静态网站.另外,我已经为两个'索引文档名称'和'错误文档名称'定义了index.html.这是因为我希望我的 JavaScript 应用程序处理 404 响应.

I have succesfully set up a static website on Azure Blob storage using the $web container as advised within the Microsoft documentation. In addition, I have defined index.html for both the 'Index Document Name' and the 'Error Document Name'. This is because I want my JavaScript application to handle the 404 responses.

但是,当查看 Chrome 中的网络选项卡时,我可以看到为我请求的 URL 抛出了 404,尽管该页面实际上可以正常工作.

However, when looking at the network tab in Chrome, I can see that a 404 is being thrown for the URL that I am requesting, despite the page actually working.

我的理论如下:

  • Azure 检查文件"是否存在
  • 如果文件存在,则返回它
  • 如果文件不存在,它会抛出一个 404 并将 URL 重写为错误文档名称",即 index.html 在我的情况下(因此我的页面仍然有效)
  • Azure checks to see if the 'file' exists
  • If the file exists, it returns it
  • If the file doesn't exist, it throws a 404 and rewrites the url to the 'Error Document Name' i.e. index.html in my case (hence my pages still work)

我的问题是我的网址是干净的网址,例如:

The problem I have is that my URLs are clean urls, for example:

/activities/some-slug 永远不会作为文件存在,这只是告诉我的 JavaScript 应用程序在哪里路由请求,即加载什么视图.

/activities/some-slug is never going to exist as a file, this just tells my JavaScript application where to route the request i.e. what view to load.

需要说明的是,页面确实可以工作,因为它仍在将 404 错误路由到 index.html.

Just to be clear, the page does work because it is still routing 404 errors to index.html.

如何告诉 Azure blob 将所有内容绝对路由到 index.html 并让我的应用在必要时抛出 404?

How can I tell Azure blob to just route absolutely everything to index.html and let my app throw the 404 if necessary?

我们确实已经设置了 Premium Verizon CDN,因为我最初不知道 Azure Blob 上的静态网站选项.如果 CDN 是最佳途径,请您提供有关如何配置 CDN 以提供我想要的内容的说明吗?

We do have a Premium Verizon CDN set up already because I was not originally aware of the static website option on Azure Blob. If the CDN is the best route, please can you provide instructions on how to configure the CDN to provide what I am looking for?

我阅读了大量文章(特别是 这个) 并且我相信可能有各种解决方案,即 Azure Functions、代理、CDN 等.也就是说,没有提供明确的说明来实际处理那些特定的服务.

I have read numerous articles (specifically the comments in this one) and I believe that there may be various solutions i.e. Azure Functions, Proxy, CDN etc. That said, none provide clear instructions of what to actually do with those specific services.

我通常在 AWS 上工作,所以不熟悉所有 Azure 服务和可用配置.

推荐答案

我想我找到了解决方案

  1. 添加新规则
  2. 条件:URL 文件扩展名

  1. Add a new rule
  2. Condition: URL file extension

一个.运算符:小于

B.扩展:1

c.案例转换:无转换

[这基本上意味着所请求的 URL 没有文件(扩展名),而是由应用路由处理的应用路由]

[This basically means that the URL requested has no file (extension) but is a route of the app which will be taken care of by the app routing]

操作:URL 重写

一个.源模式:/

B.目的地:/index.html

b. Destination: /index.html

c.保留不匹配的路径:否

c. Preserve unmatched path: No

.

这篇关于在 Azure Blob 存储上使用静态网站选项托管 SPA(干净的 URL 和深层链接)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆