Rack CORS re config fix

James Peret 10 年之前
父節點
當前提交
51acf28286
共有 1 個文件被更改,包括 5 次插入2 次删除
  1. 5 2
      config.ru

+ 5 - 2
config.ru

@@ -5,7 +5,7 @@ run Sinatra::Application
5 5
 
6 6
 use Rack::Cors do
7 7
   allow do
8
-    origins 'localhost:3000', '127.0.0.1:3000',
8
+    origins /http:\/\/localhost:\d{1,3}(:\d+)?/, '127.0.0.1:3000',
9 9
             /http:\/\/192\.168\.0\.\d{1,3}(:\d+)?/
10 10
             # regular expressions can be used here
11 11
 
@@ -13,7 +13,10 @@ use Rack::Cors do
13 13
     resource '/file/at/*',
14 14
         :methods => [:get, :post, :put, :delete, :options],
15 15
         :headers => 'x-domain-token',
16
-        :expose  => ['Some-Custom-Response-Header'],
16
+        :expose  => [ 'Access-Control-Allow-Origin' => '*',
17
+                      'Access-Control-Allow-Methods' => 'POST, PUT, PATCH, DELETE, GET, OPTIONS',
18
+                      'Access-Control-Request-Method' => '*',
19
+                      'Access-Control-Allow-Headers' => 'Origin, X-Requested-With, Content-Type, Accept, Authorization'],
17 20
         :max_age => 600
18 21
         # headers to expose
19 22
   end