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


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 :


How i can fix it ?


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] }

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

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

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?

This link don’t work too, https can be is the problem ?


Finally, the subdomain without https is the problem.

My post is resolved :slight_smile: