Websites/lib/middleware/dev_host.rb

25 lines
662 B
Ruby

# frozen_string_literal: true
module Middleware
class DevHost
DEFAULT_HOST = "v2.yiff.rest"
def initialize(app)
@app = app
end
def call(env)
request = Rack::Request.new(env)
domain = request.params["domain"].presence || DEFAULT_HOST
domain = OtherRoutes::ADMIN_DOMAIN if %w[/jobs /exceptions].any? { |p| request.path.start_with?(p) }
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
@app.call(env)
end
end
end