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
Chaika
Chaika•5mo ago
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.
Chaika
Chaika•5mo ago
(in case it's worth clarifying for the first part, it'd be like sub.ext.domain -> cname -> uselessdomainincf.com -> runs Worker
johtso
johtsoOP•5mo ago
ahhh ok, I was thinking.. I need a zone first so I'd have to buy another domain
Chaika
Chaika•5mo ago
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
johtso
johtsoOP•5mo ago
thanks! was looking at those xyz domains
Chaika
Chaika•5mo ago
yea, end users wouldn't ever see it
johtso
johtsoOP•5mo ago
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?
Chaika
Chaika•5mo ago
yea, you can just add external subdomains to it directly under Pages's Custom Domains tab
johtso
johtsoOP•5mo ago
could i use _redirects to proxy to my worker?
Chaika
Chaika•5mo ago
Doesn't support proxying to external stuff, only actual redirects
johtso
johtsoOP•5mo ago
oh yeah "Proxying will only support relative URLs on your site. You cannot proxy external domains."
Chaika
Chaika•5mo ago
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.
johtso
johtsoOP•5mo ago
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 😢
Want results from more Discord servers?
Add your server