Cloudflare worker custom subdirectory?

I have set up my worker with Cloudflare workers successfully, and was wondering if it’s possible to move it over to a custom subdirectory? I got it working with subdomains using routes and DNS, but seems like subdirectories is a bit different.
Basically I wanna route workers.dev site to example.com/customdirectory

So what I’m trying to achieve:
my customnamehere.workers.dev site is routed to custom.example.com.
What I want is:
customnamehere.workers.dev OR custom.example.com to be accessed from example.com/customdirectory for example.

Is it possible, if so are there any tutorials out there? Been stuck with this for hours now, tried every possible way I could think of.

Are you editing the worker from the dashboard or from Wrangler CLI?

1 Like

Dashboard.

  1. Make sure your domain is proxied.
  2. Create your worker.
  3. Assign that worker to the route example.com/customdirectory/*

Worker example that returns the current url:

addEventListener('fetch', event => {
    event.respondWith(handleRequest(event));
});


const handleRequest = async (event) => {
	return new Response(event.request.url);
}

2 Likes

Okay, I see now, thanks. There seems to be issue with the worker script I’m using, that’s why it wasn’t working for me before.
Do you happen to know how to include separate worker in another worker?
Let’s say I want to include/show/display worker1 in worker2 script.

Do you have examples of what you are trying to do?

1 Like

Yes. The answer you gave me works, but it doesn’t work with the worker I have for some reason. I don’t know how familiar you are with cf-workers status page . It’s an open source status page, and I’m trying to get it to work in my subdirectory. It works perfectly with subdomain but not with subdirectory.