OEmbed::Providersでhttpsリクエスト時の証明書確認を無効にしたいっ!
2021年2月20日
以下のような感じで、oembedの対象ドメインを追加することはできるんですが、
# 追加
example = OEmbed::Provider.new("https://example.com/oembed")
example << "https://example.com/users/*"
OEmbed::Providers.register(example)
# デフォルト
OEmbed::Providers.register_all
実際にこのドメインをチェックしようとすると、
class OembedController < ApplicationController
def show
OEmbed::Providers.get('https://example.com/oembed')
end
end
これをdevelopment環境(SSL証明書がない状態)で動かそうとすると、証明書エラーになってしまうので、OEmbed::Providersの中身を確認した感じ、実際のリクエストはNet::HTTPを使ってるようです。
そこで以下の設定を追加すれば、証明書のエラーを無視してリクエストを送ることができるようになります。
(もちろんproduction環境は証明書のエラーは発生しないはずなので、development環境だけ対象にします)
if Rails.env.development? OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE end
ただこの設定入れるとRails起動時にワーニングがでます…