Browse Source

Activate CORS

Lou 3 years ago
parent
commit
66038c6afb
3 changed files with 13 additions and 10 deletions
  1. 1
    1
      Gemfile
  2. 3
    0
      Gemfile.lock
  3. 9
    9
      config/initializers/cors.rb

+ 1
- 1
Gemfile View File

@@ -23,7 +23,7 @@ gem 'puma', '~> 5.0'
23 23
 gem 'bootsnap', '>= 1.4.4', require: false
24 24
 
25 25
 # Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible
26
-# gem 'rack-cors'
26
+gem 'rack-cors'
27 27
 
28 28
 group :development, :test do
29 29
   # Call 'byebug' anywhere in the code to stop execution and get a debugger console

+ 3
- 0
Gemfile.lock View File

@@ -100,6 +100,8 @@ GEM
100 100
       nio4r (~> 2.0)
101 101
     racc (1.5.2)
102 102
     rack (2.2.3)
103
+    rack-cors (1.1.1)
104
+      rack (>= 2.0.0)
103 105
     rack-test (1.1.0)
104 106
       rack (>= 1.0, < 3)
105 107
     rails (6.1.3.1)
@@ -171,6 +173,7 @@ DEPENDENCIES
171 173
   jwt (~> 2.2)
172 174
   listen (~> 3.3)
173 175
   puma (~> 5.0)
176
+  rack-cors
174 177
   rails (~> 6.1.3, >= 6.1.3.1)
175 178
   rails-erd
176 179
   spring

+ 9
- 9
config/initializers/cors.rb View File

@@ -5,12 +5,12 @@
5 5
 
6 6
 # Read more: https://github.com/cyu/rack-cors
7 7
 
8
-# Rails.application.config.middleware.insert_before 0, Rack::Cors do
9
-#   allow do
10
-#     origins 'example.com'
11
-#
12
-#     resource '*',
13
-#       headers: :any,
14
-#       methods: [:get, :post, :put, :patch, :delete, :options, :head]
15
-#   end
16
-# end
8
+Rails.application.config.middleware.insert_before 0, Rack::Cors do
9
+  allow do
10
+    origins 'example.com' # To be changed
11
+
12
+    resource '*',
13
+      headers: :any,
14
+      methods: [:get, :post, :put, :patch, :delete, :options, :head]
15
+  end
16
+end

Loading…
Cancel
Save