Skip to content

Commit

Permalink
config: #1 cors on rails
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianrbp committed Aug 2, 2024
1 parent efe648d commit 40cc4f4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
7 changes: 4 additions & 3 deletions backend/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ ruby "3.3.4"
gem "rails", "~> 7.1.3", ">= 7.1.3.4"
# [1.1] APIs
# JSON APIs
# gem "jbuilder"
gem "jbuilder"

# Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin Ajax possible
# gem "rack-cors"
gem "rack-cors"


# [2] Storage
Expand Down Expand Up @@ -79,5 +79,6 @@ group :development do
# gem "spring"
# Errors
gem "better_errors", "~> 2.10"
# Models
gem "annotate", "~> 3.2"
end

11 changes: 11 additions & 0 deletions backend/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ GEM
minitest (>= 5.1)
mutex_m
tzinfo (~> 2.0)
annotate (3.2.0)
activerecord (>= 3.2, < 8.0)
rake (>= 10.4, < 14.0)
base64 (0.2.0)
better_errors (2.10.1)
erubi (>= 1.0.0)
Expand Down Expand Up @@ -138,6 +141,9 @@ GEM
irb (1.14.0)
rdoc (>= 4.0.0)
reline (>= 0.4.2)
jbuilder (2.12.0)
actionview (>= 5.0.0)
activesupport (>= 5.0.0)
listen (3.9.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
Expand Down Expand Up @@ -194,6 +200,8 @@ GEM
nio4r (~> 2.0)
racc (1.8.1)
rack (3.1.7)
rack-cors (2.0.2)
rack (>= 2.0.0)
rack-session (2.0.0)
rack (>= 3.0.0)
rack-test (2.1.0)
Expand Down Expand Up @@ -289,6 +297,7 @@ PLATFORMS
x86_64-linux

DEPENDENCIES
annotate (~> 3.2)
better_errors (~> 2.10)
bootsnap
database_cleaner (~> 2.0)
Expand All @@ -298,9 +307,11 @@ DEPENDENCIES
faker (~> 3.4)
guard (~> 2.18)
guard-rspec (~> 4.7)
jbuilder
pg (~> 1.1)
pry-rails (~> 0.3.11)
puma (>= 5.0)
rack-cors
rails (~> 7.1.3, >= 7.1.3.4)
rspec-rails (~> 6.1)
shoulda-matchers (~> 6.2)
Expand Down
20 changes: 11 additions & 9 deletions backend/config/initializers/cors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@

# Read more: https://github.com/cyu/rack-cors

# Rails.application.config.middleware.insert_before 0, Rack::Cors do
# allow do
# origins "example.com"
#
# resource "*",
# headers: :any,
# methods: [:get, :post, :put, :patch, :delete, :options, :head]
# end
# end
Rails.application.config.middleware.insert_before 0, Rack::Cors do
allow do
origins "*"
# origins "http://vue:8080"

resource "*",
headers: :any,
# credentials: true,
methods: [:get, :post, :put, :patch, :delete, :options, :head]
end
end

0 comments on commit 40cc4f4

Please sign in to comment.