Module: Supabase::Rails::CORS

Defined in:
lib/supabase/rails/cors.rb

Constant Summary collapse

SUPABASE_HEADERS =
%w[
  authorization
  x-client-info
  apikey
  content-type
  x-retry-count
].join(", ").freeze
SUPABASE_METHODS =
%w[
  GET
  POST
  PUT
  PATCH
  DELETE
  OPTIONS
].join(", ").freeze
DEFAULT_HEADERS =
{
  "Access-Control-Allow-Origin" => "*",
  "Access-Control-Allow-Headers" => SUPABASE_HEADERS,
  "Access-Control-Allow-Methods" => SUPABASE_METHODS
}.freeze

Class Method Summary collapse

Class Method Details

.add_headers(headers, config = nil) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/supabase/rails/cors.rb', line 37

def add_headers(headers, config = nil)
  return headers if config == false

  cors = build_headers(config)
  merged = headers.dup
  cors.each { |key, value| merged[key] = value }
  merged
end

.build_headers(config = nil) ⇒ Object



30
31
32
33
34
35
# File 'lib/supabase/rails/cors.rb', line 30

def build_headers(config = nil)
  return {} if config == false
  return config if config.is_a?(Hash)

  DEFAULT_HEADERS
end