Feedback on Cloudflare Pages

Hey folks!

I’ve had plenty of experience hosting static websites (SPA/JAMStack) on S3 + CloudFront and I’d love to share what I require of Cloudflare Pages, because I can’t wait to switch over and I really hope Cloudflare will support those edge cases that I encountered.

I recently ran into an issue with GatsbyJs, which is basically a ReactJS framework that generates static pages with ease, and other cool things! The issue that I encountered was that I created a client-only path for /app/* requests, but S3 returns 404 for those pages because they don’t exist on S3. So of course I could simply make S3 return /index.html for requests that return 404 and GatsbyJS will generate the page based on the path. But… it’s not that simple, because /index.html was pre-rendered for the frontpage and it can cause all kind of issues.

My first idea was to check if CloudFront supports custom error response based on path, but unfortunately that isn’t supported, they only support custom error response based on response code, e.g. 404, which wasn’t enough. Eventually I figured out a way. It was to associate my CloudFront distribution to a Lambda for origin requests. This will basically make all requests go through a custom serverless Node.js function, and in that function I simply made CloudFront request for /app/index.html on S3 for all /app/* requests. Problem solved!

Based on this experience, I would love if Cloudflare Pages supported something similar, e.g. by having the ability to choose which file to return if 404 is encountered based on path.

  • 404 for app/* would return /app/index.html
  • all other 404 requests would return /index.html

I hope my feedback makes sense. Please don’t hesitate to comment if you have any further questions about this feedback.

Pages follow the logic of your application. If your Gatsby responds on localhost with custom 404, Pages should do the same thing.

If you don’t have access to Pages yet, you can deploy Gatsby via Workers and test how it behaves: https://www.gatsbyjs.com/docs/deploying-to-cloudflare-workers/.

This topic was automatically closed after 14 days. New replies are no longer allowed.