2017-06-05 20:09:29 +10:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-06-08 04:09:25 +10:00
|
|
|
class Api::V1::StreamingController < Api::BaseController
|
2017-06-05 20:09:29 +10:00
|
|
|
def index
|
2024-01-11 02:05:46 +11:00
|
|
|
if same_host?
|
2019-10-09 16:10:46 +11:00
|
|
|
not_found
|
2023-02-08 17:07:36 +11:00
|
|
|
else
|
|
|
|
redirect_to streaming_api_url, status: 301
|
2017-06-05 20:09:29 +10:00
|
|
|
end
|
|
|
|
end
|
2019-10-09 16:10:46 +11:00
|
|
|
|
|
|
|
private
|
|
|
|
|
2024-01-11 02:05:46 +11:00
|
|
|
def same_host?
|
|
|
|
base_url = Addressable::URI.parse(Rails.configuration.x.streaming_api_base_url)
|
|
|
|
request.host == base_url.host && request.port == (base_url.port || 80)
|
|
|
|
end
|
|
|
|
|
2019-10-09 16:10:46 +11:00
|
|
|
def streaming_api_url
|
|
|
|
Addressable::URI.parse(request.url).tap do |uri|
|
2024-01-02 23:27:51 +11:00
|
|
|
base_url = Addressable::URI.parse(Rails.configuration.x.streaming_api_base_url)
|
|
|
|
uri.host = base_url.host
|
|
|
|
uri.port = base_url.port
|
2019-10-09 16:10:46 +11:00
|
|
|
end.to_s
|
|
|
|
end
|
2017-06-05 20:09:29 +10:00
|
|
|
end
|