EVN['CDN_HOST'] messes up the generated URL

So according to the docs, I’m supposed the put the following code in my config/routes.rb:

route_for(
      :rails_service_blob_proxy,
      model.signed_id,
      model.filename,
      options.merge(host: ENV['CDN_HOST'])
    )

Assuming my CDN host is: cdn.my-website.com The problem now is: the URLs that are generated via calling cdn_img_url look like the following:

https://cdn.my-webstie.com/rails/active_storage/blobs/proxy/........file_name.png

CDN host URL isn’t hosting any Rails app, so what am I missing here?

can you share the source code of cdn_img_url method?

Here’s the complete according to the documentation:

# config/routes.rb
direct :cdn_image do |model, options|
  expires_in = options.delete(:expires_in) { ActiveStorage.urls_expire_in }

  if model.respond_to?(:signed_id)
    route_for(
      :rails_service_blob_proxy,
      model.signed_id(expires_in: expires_in),
      model.filename,
      options.merge(host: ENV['CDN_HOST'])
    )
  else
    signed_blob_id = model.blob.signed_id(expires_in: expires_in)
    variation_key  = model.variation.key
    filename       = model.blob.filename

    route_for(
      :rails_blob_representation_proxy,
      signed_blob_id,
      variation_key,
      filename,
      options.merge(host: ENV['CDN_HOST'])
    )
  end
end

I just replied your question on SO ruby on rails - Using CDN with ActiveStorage, what should be ENV['CDN_HOST']? - Stack Overflow