pointing a custom subdomain to worker
I'm struggling to figure out how I can get a custom subdomain connected to my worker when my DNS is hosted externally
Is this impossible without a business plan?
There must be some way to get this to work.
I currently have my subdomain pointing at a netlify site and it works fine.
13 Replies
If you want to use Workers:
You can use CF for SaaS (SSL/TLS -> Custom Hostnames) with any website you have added/can add, and use the Worker as your fallback origin: https://developers.cloudflare.com/cloudflare-for-platforms/cloudflare-for-saas/start/advanced-settings/worker-as-origin/. You can add 100 custom hostnames for free.
If you want to use something more like netlify, Cloudflare Pages which has unlimited static asset serving and functions which are Workers with some magic, supports Custom Subdomains for external domains out of the box. Under the hood it uses CF For SaaS itself
Cloudflare Docs
Workers as your fallback origin · Cloudflare for Platforms docs
Learn how to use a Worker as the fallback origin for your SaaS zone.
(in case it's worth clarifying for the first part, it'd be like
sub.ext.domain -> cname -> uselessdomainincf.com -> runs Worker
ahhh ok, I was thinking.. I need a zone first
so I'd have to buy another domain
a few domain extensions like .win, .download, etc from the cf registrar cost ~4.16 or so, or numeric .xyz like 9958454.xyz from porkbun and such for ~99c/year or so
thanks! was looking at those xyz domains
yea, end users wouldn't ever see it
but if I make a cloudflare pages site I should be able to get it working with an externally dns hosted subdomain without buying another domain?
but I'd have to turn my worker into a pages function?
yea, you can just add external subdomains to it directly under Pages's Custom Domains tab
could i use _redirects to proxy to my worker?
Doesn't support proxying to external stuff, only actual redirects
oh yeah "Proxying will only support relative URLs on your site. You cannot proxy external domains."
Functions have file based routing that works well built in: https://developers.cloudflare.com/pages/functions/routing/, or depending on what you're trying to do, you also have advanced mode: https://developers.cloudflare.com/pages/functions/advanced-mode/ which gives you the full worker syntax but you have to handle all requests
Cloudflare Docs
Advanced mode · Cloudflare Pages docs
Advanced mode allows you to develop your Pages Functions with a _worker.js file rather than the /functions directory.
currently using otel-cf-workers.. which I guess doesn't work with pages
currently just trying to just to a really simple migration with a build step like this
esbuild --bundle src/index.ts --format=esm --outfile=dist/_worker.js
@Chaika the result of spending a day on this yesterday was that my incoming webhook requests are getting blocked by cloudflare browser integrity. And there's no way of relaxing the firewall for a subdomain added through pages. And to add a subdomain as a proper zone requires paying $200 a month 😢