【问题标题】:How Protect static assets in cloud flare CDN?Cloudflare CDN 中如何保护静态资产?
【发布时间】:2021-12-14 04:03:35
【问题描述】:

我想使用 cloudflare cdn 提供静态内容,但它应该只能由经过身份验证的用户访问。现在资源保存在 firebase 存储中并遵循本教程。 https://www.ayrshare.com/how-to-put-a-cdn-in-front-of-firebase-cloud-storage/.

但这利用了公众可以访问的存储桶。我想做这个

https://blog.cloudflare.com/token-authentication-for-cached-private-content-and-apis/ 但如果我将它存储在谷歌云存储中,它将可供公众访问。有没有其他方法可以提供受保护的静态内容?

【问题讨论】:

    标签: firebase google-cloud-platform google-cloud-storage cdn cloudflare


    【解决方案1】:

    您可以创建一个Worker,它将在您的 Cloudflare 域上运行(在配置的路由上),然后使用 Worker 和 Google Cloud 之间的身份验证从 Google Cloud 中提取所需的资产。

    有几个代码示例here 展示了如何使用Fetch API。还可以在这里查看 other examples 向您展示如何在 Workers 中使用 Cache API 从 CDN 提供内容,而不是每次都从 Google Cloud 中提取内容。

    【讨论】: