2024-05-06 07:47:53 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2024-05-03 23:06:08 +00:00
|
|
|
module Middleware
|
|
|
|
class DevHost
|
2024-10-13 06:04:55 +00:00
|
|
|
DEFAULT_HOST = "v2.yiff.rest"
|
2024-05-03 23:06:08 +00:00
|
|
|
def initialize(app)
|
|
|
|
@app = app
|
|
|
|
end
|
|
|
|
|
|
|
|
def call(env)
|
|
|
|
request = Rack::Request.new(env)
|
2024-05-06 07:47:53 +00:00
|
|
|
domain = request.params["domain"].presence || DEFAULT_HOST
|
2024-10-13 06:04:55 +00:00
|
|
|
domain = OtherRoutes::ADMIN_DOMAIN if %w[/jobs /exceptions].any? { |p| request.path.start_with?(p) }
|
2024-05-03 23:06:08 +00:00
|
|
|
|
2024-05-06 07:47:53 +00:00
|
|
|
if Rails.env.development? && domain
|
|
|
|
env["websites.dev_host"] = domain
|
|
|
|
env["websites.dev_domain"] = domain.split(".").last(2).join(".")
|
|
|
|
env["websites.dev_subdomains"] = domain.split(".")[0..-3].join(".")
|
|
|
|
end
|
2024-05-03 23:06:08 +00:00
|
|
|
|
|
|
|
@app.call(env)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|