Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ActiveStorage unable to render attachment URLs across subdomains #32129

Closed
tylerbodway opened this issue Feb 27, 2018 · 5 comments
Closed

ActiveStorage unable to render attachment URLs across subdomains #32129

tylerbodway opened this issue Feb 27, 2018 · 5 comments
Milestone

Comments

@tylerbodway
Copy link

tylerbodway commented Feb 27, 2018

I am developing a mutli-subdomain application, and because of that I utilize lvh.me as my host to be able to navigate those subdomains locally.

As of 6fb3ac1 on the ActiveStorage Disk service, the host was defaulted to localhost:3000 which forces me to set the host: setting in my config/storage.yml

local:
  service: Disk
  root: <%= Rails.root.join("storage") %>
  host: http://lvh.me:5000

I would expect that attached images would be able to look at the current environment's server and build the url from there. I would expect that if I upload an image on admin.lvh.me:5000, it would be able to render on lvh.me:5000

Because I have to explicity set the host, the generated image urls are only available on the subdomain I specify in the config/storage.yml

With the configuration as seen above, when I am on the admin subdomain I receive this error when displaying an attached image

screen shot 2018-02-27 at 12 14 18 pm

Without anyway to dynamically set that ActiveStorage url host, I'm not sure how to get around this issue.

Ruby: 2.4.2
Rails: 5.2.0.rc1

@42he
Copy link

42he commented Feb 28, 2018

This was introduced in the Commit

Provide a sensible default host 6fb3ac1

The problem is, with setting host to "localhost" you don't get relative URLs. But relative URLs for the Disk Storage Adapter are fine.

And there is a second BUG: When you set another host in the yml file, AS will ignore the setting. I'ts always "localhost".

@pixeltrix
Copy link
Contributor

@42he when you say that AS ignores the setting, is that the generated url is using 'localhost' but ActiveStorage::Blob.service.host is configured correctly? Testing locally seems to configure the host correctly on the service.

@42he
Copy link

42he commented Feb 28, 2018

I have the mirror service:

local:
service: Disk
root: <%= Rails.root.join('storage') %>
host: https://example.com
amazon:
service: S3
(...)
mirror:
service: Mirror
primary: local
mirrors: [amazon]

irb(main):001:0> ActiveStorage::Blob.service.host
NoMethodError: undefined method `host' for #ActiveStorage::Service::MirrorService:0x007f861fe988e0
from (irb):1

The links all start with localhost:3000

I don't know if it setted the host correct before your commit, but with no host setting i got "relative" URLS witch worked perfekly fine.

@pixeltrix
Copy link
Contributor

@42he what do you get if you do ActiveStorage::Blob.service.primary.host ?

I think what you may be seeing is the stable url in the view which then gets redirected to the service url by the ActiveStorage::BlobsController#show action.

@stevenharman
Copy link
Contributor

The latest fix for this, ccac681, breaks any non-browser direct upload clients. e.g., an iOS or Android native client as the direct upload url is no longer a url, but a relative path. I mentioned this same case in #32139. But it was OK there because we could still set a host option to something like host: my-machine.local:5000 and things would work. (See: #32139 (comment)).

Is there a reason to not allow the host option? Is there something different that non-browser ActiveStorage clients should be doing?

/cc @georgeclaghorn @pixeltrix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants