dragonfly icon indicating copy to clipboard operation
dragonfly copied to clipboard

Configure host for file datastore URLs

Open epidemian opened this issue 9 years ago • 3 comments

Hi!

I was trying to configure Dragonfly to return full URLs, and noticed that configuring the url_host option only affects the Job#url method, but not the app.remote_url_for (using the file datastore):

require 'dragonfly'

Dragonfly.app.configure do
  url_host 'http://localhost:4567'
  datastore :file, server_root: '', root_path: 'public/dragonfly'
  verify_urls false
end

p Dragonfly.app.fetch('some-file').url # => "http://localhost:4567/W1siZiIsInNvbWUtZmlsZSJdXQ"
p Dragonfly.app.remote_url_for('some-file') # => "public/dragonfly/some-file"

(Passing a host: parameter also works for url, but to for remote_url_for)

I wanted to generate image URLs images directly pointing to the local files and serve them statically. And i wanted those to be absolute URLs instead of relative if possible.

I there a reason the url_host doesn't work on remote URLs for the file datastore? I'm probably missing something. Or, is there a way to configure that?

Thanks!

epidemian avatar Mar 21 '16 13:03 epidemian

the reason is that as a rule, the remote_url is quite separate from the other urls as it comes straight from the datastore, e.g. if you configured it to use S3 storage, you definitely wouldn't want it to have the same host, so it makes sense to configure both separately.

But yes, the FileDataStore only returns relative paths at the moment. Maybe the FileDataStore should take an option allowing the host to be specified. In the meantime you'll have to add in the host manually I'm afraid.

By the way, if you don't want "public" to appear in the url, set "server_root" as "public"

markevans avatar Mar 21 '16 22:03 markevans

@markevans Thanks for the thorough response!

So yes, i can see now that it makes total sense that url_host on the Dragonfly.app configuration doesn't affect the URLs of the file datastore.

You can close this issue if you prefer. Though, if you think that adding an option to the file datastore for configuring the URL host would be a worthy addition, i could give it a shot :smiley:

By the way, if you don't want "public" to appear in the url, set "server_root" as "public"

Thanks, yeah, i discovered that shortly after submitting this issue hehe.

epidemian avatar Mar 22 '16 03:03 epidemian

sure if you fancy it/have time - personally I reckon the option should be "url_host", given to the file data store, if that makes sense.

markevans avatar Mar 22 '16 13:03 markevans