#Need help with custom hostname api

121 messages · Page 1 of 1 (latest)

deep gyro
#

I am working on a website builder saas platform, like wordpress, everything works great, starting from the r2 buckets to the kv namespaces, where users export their project into a subdomain url, but now I am trying to add a custom hostname feature where users will be able to map their own business domain with the exported subdomain url. So I used cloudflare for saas, cloudflare custom hostname api. It looks fine, the custom hostname status and the certifictate status are all active and green after user verified their domain, but when they visit their domain, it says 404 not found, even though every other thing works great, I am really confused of how to pull this off, as I am working with this for the first time, any comments on this would be really helpful, hope you understand what I am trying to say, if you need any more details, please let me know.

crystal sandBOT
#
Support AI

I understand your concern. Based on the provided documentation, I'd like to offer some insights.

When adding a custom domain, the domain will not verify if Cloudflare cannot validate a request for an SSL certificate on that hostname. In order for the SSL to validate, ensure Cloudflare Access or a Cloudflare Worker is allowing requests to the validation path: http://{domain_name}/.well-known/acme-challenge/*. (Source: https://developers.cloudflare.com/pages/platform/known-issues/)

Additionally, it's essential to review the Hostname prioritization guidelines as wildcard custom hostnames behave differently than an exact hostname match. (Source: https://developers.cloudflare.com/cloudflare-for-platforms/cloudflare-for-saas/start/advanced-settings/apex-proxying/setup/)

To troubleshoot the 404 error, you may want to check the DNS settings and ensure that the custom hostname is correctly configured. You can also try checking the Cloudflare API response for any errors or warnings related to the custom hostname.

If you're still unsure, please provide more details about your setup, such as the API response and the DNS settings, and I'll try to help you further.

mossy bronze
deep gyro
mossy bronze
#

Is your server configured to handle the custom domain or only your own subdomain?

deep gyro
#

Yeah it is configured, my users can already add the cname records to their own business domain and can also successfully verify those from my saas itself, through the cloudflare custom hostname api, I can also see the status at the selection and tls section in my cloudflare dashboard that the domain aaded for that user is green and active but, when the user visits their domain, it says 404, example: my saas is brivovt.com, so the user exported project url is "anything.brivovt.com" which loads without any problem, then user adds this exported subdomain in his own business(business.com) dns panel like "cname: project.business.com, value: anything.brivovt.com" but when he visits project.business.com, it says 404 not found while anything.brivovt.com works!!

deep gyro
mossy bronze
#

Ok, can you just confirm for me where the users websites are hosted? On your own server running apache/nginx? Or completely on Cloudflare?

deep gyro
#

Users website are outside cloudflare

#

It is in godaddy

mossy bronze
#

And on GoDaddy, did you add the custom hostname (project.business.com)?

deep gyro
#

And the backend of my saas is in gcp

mossy bronze
#

In the Cloudflare Custom Hostnames, do you use the fallback Origin or a Custom Origin for every custom hostname?

deep gyro
#

Which I even configured in by backend also

mossy bronze
#

ok, so using a custom origin means that the SNI is changed to the custom origin

#

So Cloudflare will send the custom hostname as the HOST header, but the custom origin as the SNI

#

Is it the same origin for all sites?

deep gyro
#

Yeah

mossy bronze
#

Then I'd consider using the fallback origin rather than custom origins

#

On GoDaddy, do you use nginx/apache or something like that?

deep gyro
#

No I am not using nginx/apache

#

I have never done network engineer before

#

Can I ask you a favour?

#

Is it possible for you to get on a call with me so that can show my screen on a Google meet?

#

Or should I drop all my screnshots here?

mossy bronze
#

no

#

You can post screenshots if you'd like

deep gyro
#

Ok

mossy bronze
#

Can you share a domain first where you see the 404 right now?

#

and also show what settings you made for that domain on Cloudflare?

deep gyro
#

Give me a few minutes, I am dropping them in

mossy bronze
#

sure

deep gyro
#

here is how I am adding the records from my saas to my domain "thebhargab.com" at godaddy

#

here is how I have added these records in godaddy

#

here is my ssl status at cloudflare dashboard

#

here is my entire dns table of my saas at cloudflare

mossy bronze
#

Ok, let me clarify a few things

#

you have a website builder on GCP

deep gyro
#

Yeah

mossy bronze
#

when the website is done, you deploy it on godaddy

deep gyro
#

No no

#

Go daddy has the domain only

mossy bronze
#

ahh ok, i misunderstood that part

deep gyro
#

It's the website builder which is on gcp and the dns of that website builder is on cloudflare. All the exported subdomain url that gets creates appears there only, just for testing, I bought a domain at godaddy to see if it works....

mossy bronze
#

ok, so on GCP, what settings do you make for a) your own subdomain and b) the custom hostname

deep gyro
#

The subdomains gets created on cloudflare itself, via kv namespace

mossy bronze
#

How does your service decide which website to serve for which url?

#

Where do you make the decision which website to serve?

deep gyro
#

After user is done making his website, it gets saved as a index.html file in cloudflare r2 bucket. Then I use worker and kv namespace and set that subdomain -key (book.brivovt.com) to r2publicURL(of that website) -variable.

mossy bronze
#

and have you also added the custom hostname to that configuration?

deep gyro
#

Yeah I also have it in the same kv namespace where it stores the kv pairs as (key: book.thebhargab.com, value:ther2publicurl of the website)

mossy bronze
#

Ok, so it looks to me like the Worker isn't called for the custom hostname and traffic is sent to GCP

#

Did you add the Worker via Workers Routes?

deep gyro
deep gyro
mossy bronze
#

what is the route?

deep gyro
#

tour-router.bhargabdutta.workers.dev

#

you can see that in the dns table screenshot too

#

here is the worker screenshot

mossy bronze
#

yeah, ok

#

the worker route is *.brivovt.com

#

so it doesn't work on book.whatever

#

you need a */* route

#

and then you need to make exceptions for your own domain that's not supposed to go to the worker

#

in the dashboard, go to your domain and select workers routes

#

Then you create exceptions for urls that are not supposed to go to the worker:

#

And then you create a route for everything else to go to the worker

#

Or alternatively, you can create a new route for every custom hostname that you add with the specific domain

deep gyro
mossy bronze
#

You have a route for *.brivovt.com/*

#

Which doesn't match the Route, so the Worker is not invoked

#

The route works on the url the client is using, not on the origin you have specified

#

I would recommend you do that to see if it works

deep gyro
#

Ok 1 min, I am doing what you said

#

is this what I should do??

mossy bronze
#

yeah, for example

#

Long term, you want to use a */* route so you don't have to add a new route for every custom hostname

#

But for trying, this should work

#

And it looks like it does work now

deep gyro
#

ok now this is what I have now

#

Yeah yeah

#

Thank you soooo much, let me see and test with / with multiple domains of other people

#

I'll me right back within a few hours

#

Thank you so much @mossy bronze

mossy bronze
#

Good luck 😉

deep gyro
#

I got into a problem, when I add / route, my saas itslef stops working, as it is on brivovt.com

mossy bronze
#

You need to make Worker=None Routes for the things that aren't supposed to go to the worker

#

It's usually easier that way than adding a new route for every new custom hostname

deep gyro
#

Alright I restricted all the domains that I don't want in my worker

#

It's working

#

I even tested adding records to other domains

#

These are working too

#

Thanks a lol @mossy bronze

#

Just one last thing I want to ask

#

How to learn these things??

#

I am just a frontend dev, I started learning backend dev and I have no idea how I got myself into this mess

#

Please suggest me any learning materials, book name? Courses? Anything

#

I am desperate to learn

mossy bronze
#

For product specific knowldge like this, you just learn it by spending a lot of time trying things like this.

#

Cloudflare has excellent documentation for most things, so it's always worth looking at it:

deep gyro
#

Ok

#

Thanks

#

😊

mossy bronze
#

There's also probably lots of others people that had the same question you have

#

So looking at Cloudflare Community often has the answers

#

A lot easier to search there than on Discord