Pdf files on same server don't show onebox with subdomain url

Hi,

Firstly, congratulation for this open source project.

I want make clean display for local pdf files with onebox. I saw that is not to possible with attachment, so i link pdf files from url on same server.

With or without whitelist internal hosts, That work with domains but i don’t see onebox for pdf files from subdomains url (my discourse url is on a subdomain). For my tests, All domains/subdomains redirect on the same server.


(On test screen, only domains display onebox)

I have read some posts about this, but i don’t understand the problem :


https://meta.discourse.org/t/onebox-domains-whitelist-and-subdomains/40884

How i can fix it ?

Thanks,

PS : Link work for subdomain, i can see pdf file, that’s just display problem for onebox on content.

I have search in the code,

 def self.external_onebox(url)
Rails.cache.fetch(onebox_cache_key(url), expires_in: 1.day) do
  fd = FinalDestination.new(url, ignore_redirects: ignore_redirects, ignore_hostnames: blacklisted_domains, force_get_hosts: force_get_hosts)
  uri = fd.resolve
  return blank_onebox if uri.blank? || blacklisted_domains.map { |hostname| uri.hostname.match?(hostname) }.any?

  options = {
    cache: {},
    max_width: 695,
    sanitize_config: Sanitize::Config::DISCOURSE_ONEBOX
  }

  options[:cookie] = fd.cookie if fd.cookie

  if Rails.env.development? && SiteSetting.port.to_i > 0
    Onebox.options = { allowed_ports: [80, 443, SiteSetting.port.to_i] }
  end

  r = Onebox.preview(uri.to_s, options)

  { onebox: r.to_s, preview: r&.placeholder_html.to_s }
end

I think the problem is here, no mention for the whitelist ?

return blank_onebox if uri.blank? || blacklisted_domains.map { |hostname| uri.hostname.match?(hostname) }.any?

http://www.pdf995.com/samples/pdf.pdf
This link don’t work too, https can be is the problem ?

Thanks,

Finally, the subdomain without https is the problem.

My post is resolved :slight_smile:

2 Likes