Sha256: cbb7eb498b684d1f61369a949f08f375fb81af541a0549efbff06d062360bc15

Contents?: true

Size: 1.36 KB

Versions: 3

Compression:

Stored size: 1.36 KB

Contents

require 'rack/cors'
require 'jsonapi-serializers'
require 'groupdate'
require 'net/http'
require 'useragent'
require 'jwt'
require 'bcrypt'
require_relative 'bootstraper'
require_relative 'collection'

module ForestLiana
  class Engine < ::Rails::Engine
    isolate_namespace ForestLiana

    def configure_forest_cors
      begin
        rack_cors_class = Rack::Cors
        rack_cors_class = 'Rack::Cors' if Rails::VERSION::MAJOR < 5

        config.middleware.insert_before 0, rack_cors_class do
          allow do
            hostnames = ['localhost:4200', 'app.forestadmin.com',
                         'www.forestadmin.com']
            hostnames += ENV['CORS_ORIGINS'].split(',') if ENV['CORS_ORIGINS']

            origins hostnames
            resource '*', headers: :any, methods: :any
          end
        end
        nil
      rescue => exception
        exception
      end
    end

    error = configure_forest_cors unless ENV['FOREST_CORS_DEACTIVATED']

    config.after_initialize do |app|
      unless Rails.env.test?
        if error
          FOREST_LOGGER.error "Impossible to set the whitelisted Forest " \
            "domains for CORS constraint:\n#{error}"
        end

        app.eager_load!

        # NOTICE: Do not run the code below on rails g forest_liana:install.
        Bootstraper.new(app).perform if ForestLiana.secret_key
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
forest_liana-1.4.7 lib/forest_liana/engine.rb
forest_liana-1.4.6 lib/forest_liana/engine.rb
forest_liana-1.4.5 lib/forest_liana/engine.rb