Worker | Hot Link Protection | Allow One Domain

Hello everyone!

I am a newbie when it comes to this but I would like to create a worker to allow one of my other domains use images from my main domain.

I just want to add foo to one of the allowed domains to use images from my site (example.com).

I’ve looked at the example here.

Link: https://developers.cloudflare.com/workers/examples/hot-link-protection

I just don’t know the correct code to do that and how to deploy it via Cloudflare.

Can anyone help me with it?

Right, the code in the example you gave should do what you want to achieve.

You need to install wrangler following the instructions from https://developers.cloudflare.com/workers/cli-wrangler/install-update

If you haven’t already done this, you will need to run wrangler login and follow the instructions

If you have done this, then move to the next step:

https://developers.cloudflare.com/workers/get-started/quickstarts#templates Generate a copy of the starter JavaScript template, and paste the code from the hot link example into the index.js (make sure to fill in the details).

Next, edit the wrangler.toml with your account ID, the route you want to use and the zone ID (if you want to use a custom domain)

Finally run wrangler publish

Hello DaServaJesus,

Thank you for the fast response and solution!

It seems I would have to modify my app quite a bit to achieve this as I’m using a custom php framework.

Is there a chance I can achieve the same thing with a firewall expression?

I don’t think its possible with the firewall unfortunately.