Skip to content

Commit

Permalink
Try to fix cors
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagogsr committed Jun 3, 2019
1 parent a624ee6 commit 81942a2
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions app.rb
Expand Up @@ -5,12 +5,10 @@

configure do
set :server, :puma

enable :cross_origin
set :allow_origin, ENV['ALLOWED_DOMAIN']
set :allow_methods, [:post]
end

set :allow_origin, ENV['ALLOWED_DOMAIN']
set :allow_methods, [:post, :head, :options]

helpers do
def template_file(template_name)
Expand All @@ -19,6 +17,8 @@ def template_file(template_name)
end

post '/contact' do
cross_origin

client = Mailgun::Client.new(ENV['MAILGUN_API_TOKEN'])
renderer = ERB.new(template_file('contact'))

Expand All @@ -33,12 +33,16 @@ def template_file(template_name)
end

post '/subscribe' do
cross_origin

client = Mailgun::Client.new(ENV['MAILGUN_API_TOKEN'])
client.post("lists/#{ENV['MAILGUN_MAILING_LIST']}/members", { address: params[:address], vars: '{}' })
end

options "*" do
response.headers['Allow'] = 'POST'
options '*' do
cross_origin

response.headers['Allow'] = 'POST, HEAD, OPTIONS'
response.headers['Access-Control-Allow-Headers'] = 'X-Requested-With, X-HTTP-Method-Override, Content-Type, Cache-Control, Accept'
200
end

0 comments on commit 81942a2

Please sign in to comment.