How to hide workers url with cloudflare routes?

Hi there,

As Cloudflare workers and many other products are brand new and to get better customisation i would like to hide the example.worker.dev to something like example.com/worker. I see there is Cloudflare routes but i am unable to understand how can i use that. is there an easier way for non techies to make use of Cloudflare routes to hide the workers.dev url

the workers.dev is used to submit an html form

thanks

If you add a Worker, Cloudflare will automatically deploy it to a workers.dev hostname. That is optional and you can disable that mapping.

If you want your Worker to be available under your custom domain instead, you simply map it at https://dash.cloudflare.com/?to=/:account/:zone/workers or in the settings of the Worker.

Also, Workers are not all that new any more, they have been around since 2017. In this day and age of IT, they are probably soon deprecated :wink:

1 Like

thanks @sandro

i am glad to know that i can use custom domain to host worker file. but i did not get it how to set it to use a cstom domain instead?

clicking the link you provided takes me just to Cloudflare home after login.

do you have an example screenshot or directions on where to find this setting. it might be obvious for experience Cloudflare users but i am strugling to find this your help will be greatly appreciated

thanks

You first select your domain and then you can add the mapping.

1 Like

And your domain first has to be on Cloudflare.

1 Like

i am using Cloudflare pages so evrything is on Cloudflare.

i currently use

<form action="randomtext.worker.dev"
# and i want to instead use 
<form action="example.com/submit-form"

Setting workers_dev to false in your wrangler.toml will remove the workers.dev route - this does require you to define your custom route at the same time.

Simply map the Worker to the domain as I mentioned.

You did not say that and you are in the wrong category as well.

Anyhow, Get started · Cloudflare Pages docs has that information.

hi @KianNH

  1. i do not have any wangler.toml i love the cloudflare online dashboard so i simply created a simple script directly in your online interface.

  2. everything is on cloudflare dns, web hosting and worker file. (by webhosting i mean the cloudflare pages)

  3. evrything is alread set domain with cloudflare name server, website with cloudflare pages and the worker with cloudflare worker.

now the issue comes when trying to add CSP (content security policy) and few other customisation issues i am having. i prefer to use a custom domain instead of worker.dev as using ‘self’ is way easier than having to define form, connect and other rules to submit a form to cloudflare workers. but if i can change customise the worker url to the domain like /form-submittion that will help me alot.

I think the workers cannot be added per site this makes it really difficult to manage if you have multiple workers not knowing which one is which.

Now mr. @sandro suggested to map domain to worker but i am still unabel to make use of the given example as to i am unsure what that url suppose to do or what i suppose to do to make it work.

It is there a more easier to follow guide which a non techie like me can follow while still keeping the form functionality as it is. form make a post request and then a sucess or fail message is sent back to the weebsite which make use of that with ajax.

thanks for taking the time to help

Are you using a Worker or Pages?

As for mapping a Worker to a domain, you really just need to follow the link and set up the mapping.

1 Like

Hi @sandro

the website is hosted using Cloudflare pages.

the worker is used only to recieve and send the form data from the static site hosted on Cloudflare pages.

the form is static part of the Cloudflare pages site and it submit data to worker.dev url using post method and Ajax, js

thanks

And you want to map the domain to the Worker or Pages?

Hello @sandro

i want to change the example.worker.dev url to example.com/form-submit url using Cloudflare provided services like routes so i can hide the actual url from the front end this way if a site is attacked i will simply take down that site instead of taking down the worker file

thanks

Then simply follow the steps I mentioned yesterday to map your Worker to your domain. What’s unclear exactly?

1 Like
1 Like

Hi @sandro

i am lost at the part on what i need to add for example:

route: https://example.com/form-submit
worker: i simply select the worker from th edrop down list

and thats all will it still work as before like it will send and recieve data as it is doing currenlty. Because my understanding is that it is simply going to do a redirect and the data will not be posted or is this a proven Cloudflare method for the Cloudflare workers.

thanks alot for taking the time to answer my silly questions

You indicate /form-submit as path, select the Worker, and should be all set.

1 Like

If it’s a GET request you probably want to indicate /form-submit* to match the query string as well.

1 Like

Hi @sandro

I promise this be the last question regarding this issue. can i route more than one url to the same worker?

For example 1 worker will be used for:

example.com
example-client.com
example-client2.com

can i simply add route from all those sites back to the same worker?

thanks