'Active Storage (Disk) - Access uploads across subdomains
I have a SaaS app built on subdomains per tenant. Following a Rails migration, I am trying to replace CarrierWave with ActiveStorage.
The application is structured like this:
- www.givingfire.test - marketing site
- admin.givingfire.test - admin portal
- tenant-1.givingfire.test - tenant 1
After migrating the images from CarrierWave to ActiveStorage I noticed that the images would give a 404. Then I uploaded an image in the admin.givingfire.com subdomain. It was accessible in the admin subdomain but not elsewhere.
- http://www.givingfire.test/rails/active_storage/disk/ey.../ipad-app.jpeg
[404] - http://admin.givingfire.test/rails/active_storage/disk/ey.../ipad-app.jpeg
Ok
Ideally we would put it in a S3 bucket and use CloudFront as a CDN but its not an option here and at least for a start we will be using disk storage.
I looked in ActiveStorage tables in the DB and I can't see any config pointing towards a subdomain. I wonder if it is included in the ActiveStorage::Blob#checksum.
class Upload < ApplicationRecord
has_one_attached :file
end
// It is a Trailblazer::Cell
.col-sm-3
.blog-details
- featured_image do |image|
.blog-image.mb-10
= link_to view_path do
= image_tag(\
image.file.representation(resize_to_fill: [266, 156]).processed.url,
class: 'img-responsive',
)
# config/environmentes/development.rb
require 'active_support/core_ext/integer/time'
Rails.application.configure do
# ...
config.hosts << /givingfire\.test/
config.hosts << /[a-z0-9]+\.givingfire\.test/
end
# config/storage.yml
local:
service: Disk
root: <%= Rails.root.join("storage") %>
Anyone know why and how I can solve this problem?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
