Initial thoughts on Cloudflare Pages
I’m investigating Cloudflare Pages as a hosting platform for static sites and React SPAs (amongst other things).
My first impression: This is a really simple tool which handles almost everything about hosting for me. I’m practically sold already. Hook it up to your Github (or Gitlab) repository and for the most part, everything else happens automagically. That simplicity does come with limitations though, so it might not suit everybody.
Custom domains
Hooking up a custom domain to your CF Pages site is really simple. It’s completely automated if Cloudflare manages your DNS. If not, it’s just a case of adding a CNAME
entry wherever your DNS is managed. So if I wanted to point sub.example.com
to my CF pages site at example.pages.dev
, i’d deploy this CNAME
record:
NAME | TYPE | VALUE |
---|---|---|
sub.example.com | CNAME | example.pages.dev |
I was also able to point a custom domain at the latest deployment from a specific Git branch, in this case the develop
branch:
NAME | TYPE | VALUE |
---|---|---|
sub-develop.example.com | CNAME | develop.example.pages.dev |
Environments and Previews
CF Pages can be a bit limiting if you have multiple deployment environments (e.g. development, staging, production). You can only have two sets of environment variables – one for Production and another for everything else. If you need more than that, you might want to look elsewhere for now. Luckily, it’s enough for me (for now).
Speaking of environment variables, at present you have to set them using their web interface, instead of a config file. I don’t have many, so it’s not an issue for me – but if your app makes heavy use of them, they might become a bit cumbersome to manage.
With all that said, CF Pages generates a preview build for every commit you push to Github. This is useful for getting someone else to test your work before merging it, and may reduce the need for different environments. Even if you don’t use CF Pages as your main hosting platform, the preview builds are a useful way to test your site before you go to production.
Workers and server-side code
I haven’t gotten into it yet, but CF Pages now integrates with CF Workers, which is their variant on Cloud Functions / Lambda / Serverless. You also get access to KV, their key-value data store. This means Cloudflare Pages doesn’t just need to be for static sites – there’s potentially a lot more flexibility available.
Other limitations and known issues
Handily, Cloudflare have documented some of the known issues and limitations of CF Pages.