Sha256: 9b41c9288839ee4aa746797b7ff37dec2991b255fb4dca9b354bf74b058e75b4

Contents?: true

Size: 1 KB

Versions: 39

Compression:

Stored size: 1 KB

Contents

# Custom code if Locomotive is running on the Heroku platform

if Rails.env.production? && (api_key = ENV['HEROKU_API_KEY']) && (app_name = ENV['HEROKU_APP_NAME'])
  Rails.logger.info "[Locomotive] Heroku app detected"

  require 'platform-api'

  heroku = PlatformAPI.connect(api_key)

  ActiveSupport::Notifications.subscribe('locomotive.site.domain_sync') do |name, start, finish, id, payload|
    (payload[:added] || []).each do |domain|
      next if Locomotive.config.host == domain
      begin
        heroku.domain.create(app_name, hostname: domain)
      rescue Exception => e
        Rails.logger.error "Unable to add '#{domain}' as a new domain in Heroku, error #{e.message}"
      end
    end

    (payload[:removed] || []).each do |domain|
      next if Locomotive.config.host == domain
      begin
        heroku.domain.delete(app_name, domain)
      rescue Exception => e
        Rails.logger.error "Unable to remove '#{domain}' from the list of domains in Heroku, error #{e.message}"
      end
    end
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
locomotivecms-4.2.0.alpha2 lib/generators/locomotive/install/templates/heroku.rb
locomotivecms-4.2.0.alpha1 lib/generators/locomotive/install/templates/heroku.rb
locomotivecms-4.1.1 lib/generators/locomotive/install/templates/heroku.rb
locomotivecms-4.1.0 lib/generators/locomotive/install/templates/heroku.rb
locomotivecms-4.1.0.rc1 lib/generators/locomotive/install/templates/heroku.rb
locomotivecms-4.0.3 lib/generators/locomotive/install/templates/heroku.rb
locomotivecms-4.0.2 lib/generators/locomotive/install/templates/heroku.rb
locomotivecms-4.0.1 lib/generators/locomotive/install/templates/heroku.rb
locomotivecms-4.0.0 lib/generators/locomotive/install/templates/heroku.rb
locomotivecms-4.0.0.rc0 lib/generators/locomotive/install/templates/heroku.rb
locomotivecms-4.0.0.alpha3 lib/generators/locomotive/install/templates/heroku.rb
locomotivecms-3.4.1 lib/generators/locomotive/install/templates/heroku.rb
locomotivecms-4.0.0.alpha2 lib/generators/locomotive/install/templates/heroku.rb
locomotivecms-4.0.0.alpha1 lib/generators/locomotive/install/templates/heroku.rb
locomotivecms-3.4.0 lib/generators/locomotive/install/templates/heroku.rb
locomotivecms-3.3.0 lib/generators/locomotive/install/templates/heroku.rb
locomotivecms-3.3.0.rc3 lib/generators/locomotive/install/templates/heroku.rb
locomotivecms-3.3.0.rc2 lib/generators/locomotive/install/templates/heroku.rb
locomotivecms-3.1.2 lib/generators/locomotive/install/templates/heroku.rb
locomotivecms-3.2.1 lib/generators/locomotive/install/templates/heroku.rb