Skip to content

Commit 571eef7

Browse files
authored
Merge pull request #25 from tuanle03/fix-cros-errors
Add Rack CORS gem and configure middleware for CORS support
2 parents 6037ccd + 83fc9dd commit 571eef7

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ gem 'faker'
6060

6161
gem 'blazer'
6262

63+
gem 'rack-cors'
64+
6365
# Use Sass to process CSS
6466
# gem "sassc-rails"
6567

Gemfile.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ GEM
206206
rack (2.2.8)
207207
rack-accept (0.4.5)
208208
rack (>= 0.4)
209+
rack-cors (2.0.1)
210+
rack (>= 2.0.0)
209211
rack-test (2.1.0)
210212
rack (>= 1.3)
211213
rails (7.0.4.3)
@@ -334,6 +336,7 @@ DEPENDENCIES
334336
jbuilder
335337
pg
336338
puma (~> 5.0)
339+
rack-cors
337340
rails (~> 7.0.4, >= 7.0.4.3)
338341
redis (~> 4.0)
339342
rspec-rails

config/environments/production.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,11 @@
9090

9191
# Do not dump schema after migrations.
9292
config.active_record.dump_schema_after_migration = false
93+
94+
config.middleware.insert_before(0, Rack::Cors) do
95+
allow do
96+
origins 'https://codelearn-api-72b30d70ca73.herokuapp.com/'
97+
resource '*', headers: :any, methods: %i[get post patch put delete options]
98+
end
99+
end
93100
end

0 commit comments

Comments
 (0)