Sha256: c766204b29f4c638b0956fd58732341ae764c4b1c4cfd22b1558a607e2451acb

Contents?: true

Size: 818 Bytes

Versions: 1

Compression:

Stored size: 818 Bytes

Contents

module ElocalApiSupport::EnableCors
  extend ActiveSupport::Concern
  included do
    cors_allow_all
    before_filter :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

1 entries across 1 versions & 1 rubygems

Version Path
elocal_api_support-0.1.2 lib/elocal_api_support/enable_cors.rb