Hiding External Url , Proxy images by workers?

I want to use remote server for images by hiding real url.
I have a.com/images and b.com/images
b.com/images have real images.
I want to show images of b.com in a.com website.
So i wrote a worker script by the help of some posts (thanks them)
it works as redirecting the image url but not hiding them. I can see new url on chrome development panel.
I learned that it can be made by htaccess proxy (apache mod proxy). But it didnt work yet too.
Is it possible to make this by cloudflare ? I want to hide real source for security reasons.

addEventListener(“fetch”, event => {
let requestURI = new URL(event.request.url);
if (requestURI.hostname == “www.a.com” && requestURI.pathname.startsWith("/images")) {

async function rewriteURL(request) {
var URI = new URL(request.url);
var parts = request.url.split(’/’);
var lastSegment = parts.pop() || parts.pop();

URI.protocol = “https”;
URI.hostname = “b.com”;
URI.pathname = “/images/”+lastSegment;
return fetch(URI, request);

Hi serdarors,

I feel you’re interested in the ‘Controlling origin access’ public documentation: https://developers.cloudflare.com/images/protected-origin/

Instead of responding with the rewritten URL (which causes the 301 redirect you get), you should return the fetch() call that requests the image at the source server:

async function handleRequest(request) {
  const hiddenImageOrigin = "https://b.com";
  const requestURL = new URL(request.url);
  // Append the request path such as "/images/image1.jpg" to the hiddenImageOrigin.
  // You could also process the path to add or remove directories, modify filenames, etc.
  const imageURL = hiddenImageOrigin + requestURL.path;
  // This will fetch image from the given URL, but to the website visitors this
  // will appear as a response to the original request. Visitor's browser will
  // not see this URL.
  return fetch(imageURL);

I hope that helps!