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

Not working on server with SSL #67

Closed
aleksander-tatskiy opened this issue Aug 12, 2015 · 5 comments
Closed

Not working on server with SSL #67

aleksander-tatskiy opened this issue Aug 12, 2015 · 5 comments
Labels
Milestone

Comments

@aleksander-tatskiy
Copy link

Hi guys!

I use Link Thumbnailer gem (v. 3.0.2) in my app (Rails 4.2.3, ruby 2.2.2p95). Recently I encountered a problem. On localhost Link Thumbnailer works fine. But I have staging and production servers with ssl where it does not work ( youtube link, for example: http://www.youtube.com/watch?v=6Viyt2aIOG8 ). At first I thought that configurations of my server are wrong or my code has bugs. But I checked everything over and over again. There are no bugs. I checked it in your demo http://link-thumbnailer-demo.herokuapp.com. It works fine. But when I changed link from http://link-thumbnailer-demo.herokuapp.com to https://link-thumbnailer-demo.herokuapp.com it stopped working too like in my app. Could you help to solve this problem please?

Thanks, best regards.

@gottfrois
Copy link
Owner

The demo is not working in https because it makes a http XHR request which is considered insecure. You can see the console error message in chrome.

How do you call LinkThumbnailer in your rails project?

@aleksander-tatskiy
Copy link
Author

message.rb

after_create :detect_link, :if => 'text.present?'

def detect_link
    URI.extract(text).map do |link|
        result = LinkThumbnailer.generate(link)
        if result.images.present?
          attachments.create!({:name => result.title, :remote_attachment_url => result.images.first.src.to_s, :url => result.url, :type => result.videos.andand.first.present? ? 'VideoAttachment' : 'ThumbnailAttachment',  :comments_attributes => [{:text => result.description}]})
        end
    end
    rescue Exception => e
        puts e.message
        return
end

thumbnails_controller.rb

class ThumbnailsController < LoggedUserController

  skip_load_and_authorize_resource

  def new
    begin
      render({ :json => LinkThumbnailer.generate(params[:url]) })
    rescue LinkThumbnailer::Exceptions => e
      render({ :json => e.message, :status => 422 })
    end
  end

  private

    def permitted_params
      params.require(:url)
    end

end

link_thumbnailer.rb

LinkThumbnailer.configure do |config|
  config.redirect_limit = 5
  config.verify_ssl = false
  config.http_timeout = 5
  config.attributes = [:title, :images, :description, :videos]
  config.image_limit = 1
  config.image_stats = false
end

@gottfrois
Copy link
Owner

I imagine you call the thumbnail endpoint using javascript ajax request? Do you use https there?

@aleksander-tatskiy
Copy link
Author

No, I call it from Message model.

Here. If link from youtube, attacment is not created. But from Vimeo it works

after_create :detect_link, :if => 'text.present?'

def detect_link
    URI.extract(text).map do |link|
        result = LinkThumbnailer.generate(link)
        if result.images.present?
      attachments.create!({:name => result.title, :remote_attachment_url => result.images.first.src.to_s, :url => result.url, :type => result.videos.andand.first.present? ? 'VideoAttachment' : 'ThumbnailAttachment',  :comments_attributes => [{:text => result.description}]})
    end
end
rescue Exception => e
    puts e.message
    return
 end

@gottfrois
Copy link
Owner

Really not sure what could be wrong here. Seems to be working fine with v3.0.3.

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

No branches or pull requests

2 participants