So ActiveStorage works perfectly.
I have now turned on CDN on DigitalOcean Spaces, with a personal subdomain like: https://cdn.my-website.com
I have been following this Rails official doc which states to have the following code in config/routes.rb:
# config/routes.rb
direct :cdn_image do |model, options|
if model.respond_to?(:signed_id)
route_for(
:rails_service_blob_proxy,
model.signed_id,
model.filename,
options.merge(host: ENV['CDN_HOST'])
)
else
signed_blob_id = model.blob.signed_id
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
Now, the problem is: the URL generated by calling cdn_image_url(user.profile_image)
looks like the following:
"https://cdn.my-website.com/rails/active_storage/blobs/proxy/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaEpJaWs0TWpBME9EUmxNaTA0WVRobExUUmxORGd0T0RJellpMWtOMk5rWVRVMlpXTmpaV1VHT2daRlZBPT0iLCJleHAiOm51bGwsInB1ciI6ImJsb2JfaWQifX0=--322044941e3418863e6aeff7ce802d16afe7dfb0/profile_image.png"
This URL will send the request the https://cdn.my-website.com/ and there, no Rails app is hosted. Shouldn't we use the original host here which points to the Rails app itself? Or I'm missing something obvious here.