Added support for CORS

James Peret 10 years ago
parent
commit
54b0d0492b
4 changed files with 13 additions and 0 deletions
  1. 1 0
      Gemfile
  2. 2 0
      Gemfile.lock
  3. 9 0
      config.ru
  4. 1 0
      main.rb

+ 1 - 0
Gemfile

@@ -7,6 +7,7 @@ gem 'sinatra-contrib'
7 7
 gem 'whois'
8 8
 gem 'haml'
9 9
 gem 'json'
10
+gem 'rack-cors', :require => 'rack/cors'
10 11
 
11 12
 group :test, :development do
12 13
   gem 'pry'

+ 2 - 0
Gemfile.lock

@@ -13,6 +13,7 @@ GEM
13 13
       method_source (~> 0.8.1)
14 14
       slop (~> 3.4)
15 15
     rack (1.4.1)
16
+    rack-cors (0.4.0)
16 17
     rack-protection (1.2.0)
17 18
       rack
18 19
     rack-test (0.6.3)
@@ -45,6 +46,7 @@ DEPENDENCIES
45 46
   haml
46 47
   json
47 48
   pry
49
+  rack-cors
48 50
   rb-readline
49 51
   sinatra
50 52
   sinatra-contrib

+ 9 - 0
config.ru

@@ -1,2 +1,11 @@
1 1
 require './main'
2
+require 'rack/cors'
3
+
2 4
 run Sinatra::Application
5
+
6
+use Rack::Cors do
7
+  allow do
8
+    origins  "*"
9
+    resource "*", headers: :any, methods: [:get, :post, :options]
10
+  end
11
+end

+ 1 - 0
main.rb

@@ -78,6 +78,7 @@ end
78 78
 
79 79
 get '/lookup.json' do
80 80
   content_type 'application/json'
81
+  response["Content-Type"] = "application/json"
81 82
   begin
82 83
     #cache_for_day
83 84
     parser = WhoisParser.new