Questions regarding Worker proxying

Hey there,

I spoke to a CloudFlare support engineer and they said the following was possible (it seems to be related to this article):

Suppose the following 2 URLs:

www.example.com/*
www.example.com/specific-url/

I want to route www.example.com/specific-url/ to a Netlify site but still have all my other traffic route to the normal server. The support engineer said this was possible to achieve with workers. We’re on business and cannot afford $5000/month at this stage. Please advise?

I cannot seem to find a solution for this issue.

Kind regards
Chris

There is no way to do that without workers.

You could setup a proxy server, but it would slow everything down.

Also, you get enough requests to go to 5000$/month with Workers? That would be 10B requests a month only on that path. Maybe contact sales for the Enterprise plan?

Hey there,

Thanks for the quick reply. I think you might miss-understand my question.

We cannot get enterprise, because it’s too expensive. Meaning, page rules for this is not an option.

We want to do this with workers, but not sure what code should be written to achieve this.

Hope that makes sense?

Thanks
Chris

Oh, I see…

I don’t really know if Netlify will accept the requests, but the basis would this:

if its possible you can use subdomain for that, it would solve your problem as you can easily do it in the dns tab

instead of

http://www.example.com/specific-url/

to:

http://specific-url.example.com/

Hey there,

We want to systematically rebuild a site. We want to route the requests to a new back-end. So no, a sub-domain wouldn’t work for this.

Thanks for the idea.

Chris

Thanks,

I’ll definitely check this out.

Chris

This is turning out to be a bit tricky.

We’re able to route a url to a different back-end, however, the Netlify site has a /static/ path of the resources. The paths in our site are relative, so they’re just /static/resource.jpg. So this issue now is that resources are routed to the other domain, not sure if that makes sense?

Thanks

You could rewrite the URLs in the HTML via the worker, adding the path you need… There should be an exams in the docs I linked you before…

1 Like

There’s a great write-up on the Cloudflare blog that does something similar to this with a Wordpress site – serving a WP blog as a subdirectory, instead of a subdomain:

In particular, it includes support for checking what are referred to as assetsPathnames in the Workers script code, such as /public/ or /assets/ – this sounds pretty similar to your /static/ subdirectory constraint.

I’ve used this approach for taking a Wordpress site and hosting it as a subdirectory for one my projects, at frontendjobs.tech/blog – the majority of the site is a React app, but I have a Workers script running to match any requests to /blog/* and route them to the WP site, while the rest of the site stays intact. It sounds very similar to what you’re trying to do!

2 Likes

Read more into Netlify’s TOML (netlify.toml) rules. Said TOML file allows you to achieve the same level of control as Workers but without the charge. They’ve also _headers & _redirections files, each of which allows you to even further extend one’s domain(s) configuration(s).