使用 Cloudflare 在 AWS Lambda 上部署 SSR Nuxt.js?

Deploying SSR Nuxt.js on AWS Lambda with Cloudflare?

我正在尝试通过 nuxt.js 在 Cloudflare 支持的 AWS Lambda 上实现 vue.js 服务器(-less)端渲染的类似 webshop 的网站。

相比 Cloudfront,我更喜欢 Cloudflare,因为 http/3、图像优化功能、抵御攻击的安全性、brotli 以及 Cloudflare 提供的一些开箱即用的功能。

不幸的是,我找不到任何资源,如果有人以前这样做过,也找不到要注意什么才能正常工作。

现在我的设置是这样的:

User -> Route53 -> AWS API Gateway -> AWS Lambda
 -> S3 (for static files)
 -> another AWS Lambda for dynamic data from Elasticsearch indexes

我不确定在哪里正确集成 Cloudflare。

`我发现了一篇博文和话题:

  1. 使用 Cloudflare Workers 而不是 AWS API Gateway https://news.ycombinator.com/item?id=16747420
  2. 为 Cloudfront 提供的 Lambda 创建 CNAME,但我不确定这是否会触发另一次到 Cloudfront 的往返和额外费用? https://forums.aws.amazon.com/thread.jspa?threadID=261297
  3. 将子域连接到 API-网关 https://medium.com/@bobthomas295/combining-aws-serverless-with-cloudflare-sub-domains-338a1b7b2bd
  4. 另一种解决方案可能是我直接在 Cloudflare Worker 中构建 nuxt.js,但我不确定此解决方案是否有任何缺点,因为 CPU Pro Plan 中的时间非常有限? `

此外,我还阅读了一篇文章,内容涉及通过仅允许 Cloudflare IP 来保护 API-网关免受攻击者的攻击。

你们中有人已经使用 Cloudflare 安装了 Vue + Nuxt 吗?我愿意接受任何其他建议或想法。

非常感谢! 菲利普

I am not sure where to properly integrate Cloudflare.

假设这是这里问题的症结所在,这就是使用您提供的符号的情况。

User -> Route53 -> Cloudflare -> AWS API Gateway -> AWS Lambda -> S3 -> Another lambda

基本思想是您希望 Cloudflare 成为您的 DNS (Route53) 解析的第一件事,以便它可以在 到达您的应用程序之前正确提供缓存内容.在这种情况下,将从 API 网关开始。