Subdomain must be mentioned in the worker code explicitly as hostname?

For Workes & Pages, what is the name of the domain?

example.com

What is the error number?

error522

What is the error message?

Connection timed out.

What is the issue or error you’re encountering

I tried to change my worker code in such a way that subdomain there is no need to explicitly mention the subdomain so that I can use both subdomain one and customdomain that pointed to my worker as hostname.

What steps have you taken to resolve the issue?

I couldn’t resolve the issue and had to reuse the previous code where the subdomain was mentioned explicitly. in the previous code, I used “modifyUrl()” and hardcoded my subdomain as hostname.