Sha256: e9adcd5ad757d56683fa16a3915dd8cee2c61ba95d5f51bacf233f0326359315

Contents?: true

Size: 1.12 KB

Versions: 2

Compression:

Stored size: 1.12 KB

Contents

module Simplec
  class Subdomains
    def self.matches?(request)
      simplec = request.headers['HTTP_X_ENGINE'] == 'simplec'
      present = request.subdomain.present?
      not_admin = request.subdomain != 'admin'
      subdomain = Simplec::Subdomain.find_by(name: request.subdomain)

      match = simplec || (present && not_admin && subdomain && subdomain.published)

      if match
        Thread.current[:simplec_subdomain] = subdomain
        Rails.logger.info <<-LOG
Simplec request received.
  ActionDispatch::Request#original_url: #{request.original_url}
  Simplec Engine: #{not_admin}
  LOG
      else
        if subdomain && !subdomain.published
          Rails.logger.info <<-LOG
Simplec Subdomain '#{request.subdomain}' found, but not published.
  ActionDispatch::Request#original_url: #{request.original_url}
  'admin' subdomain bypass: #{!not_admin}
  LOG
        else
          Rails.logger.info <<-LOG
Simplec Subdomain '#{request.subdomain}' was not found.
  ActionDispatch::Request#original_url: #{request.original_url}
  'admin' subdomain bypass: #{!not_admin}
  LOG
        end
      end

      match
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
simplec-0.10.1 app/constraints/simplec/subdomains.rb
simplec-0.10.0 app/constraints/simplec/subdomains.rb