streaming_controller.rb 673 B

1234567891011121314151617181920212223242526
  1. # frozen_string_literal: true
  2. class Api::V1::StreamingController < Api::BaseController
  3. def index
  4. if same_host?
  5. not_found
  6. else
  7. redirect_to streaming_api_url, status: 301, allow_other_host: true
  8. end
  9. end
  10. private
  11. def same_host?
  12. base_url = Addressable::URI.parse(Rails.configuration.x.streaming_api_base_url)
  13. request.host == base_url.host && request.port == (base_url.port || 80)
  14. end
  15. def streaming_api_url
  16. Addressable::URI.parse(request.url).tap do |uri|
  17. base_url = Addressable::URI.parse(Rails.configuration.x.streaming_api_base_url)
  18. uri.host = base_url.host
  19. uri.port = base_url.port
  20. end.to_s
  21. end
  22. end