Sha256: 0ef20f347170081123c4b6e580dc0400fc25361f83eb5cbf3d4e9d606c237f20

Contents?: true

Size: 818 Bytes

Versions: 7

Compression:

Stored size: 818 Bytes

Contents

module ElocalApiSupport::EnableCors
  extend ActiveSupport::Concern
  included do
    cors_allow_all
    before_action :enable_cors
  end

  module ClassMethods
    attr_accessor :cors_allow_origin, :cors_allow_methods, :cors_allow_headers
    def cors_allow_all
      self.cors_allow_origin  = '*'
      self.cors_allow_methods = %w(GET POST PUT DELETE).join(',')
      self.cors_allow_headers = %w(Origin Accept Content-Type X-Requested-With X-XSRF-Token).join(',')
    end
  end

  def enable_cors
    response.headers['Access-Control-Allow-Origin']  = self.class.cors_allow_origin
    response.headers['Access-Control-Allow-Methods'] = self.class.cors_allow_methods
    response.headers['Access-Control-Allow-Headers'] = self.class.cors_allow_headers
    head(:ok) if request.request_method == 'OPTIONS'
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
elocal_api_support-1.3.0 lib/elocal_api_support/enable_cors.rb
elocal_api_support-1.2.0 lib/elocal_api_support/enable_cors.rb
elocal_api_support-1.1.0 lib/elocal_api_support/enable_cors.rb
elocal_api_support-1.0.0 lib/elocal_api_support/enable_cors.rb
elocal_api_support-0.1.10 lib/elocal_api_support/enable_cors.rb
elocal_api_support-0.1.9 lib/elocal_api_support/enable_cors.rb
elocal_api_support-0.1.8 lib/elocal_api_support/enable_cors.rb