]> git.openstreetmap.org Git - rails.git/blobdiff - config/initializers/cors.rb
Allow cross-origin requests to API
[rails.git] / config / initializers / cors.rb
diff --git a/config/initializers/cors.rb b/config/initializers/cors.rb
new file mode 100644 (file)
index 0000000..6fbeb91
--- /dev/null
@@ -0,0 +1,13 @@
+require "rack/cors"
+
+# Allow any and all cross-origin requests to the API. Allow any origin, and
+# any headers. Non-browser requests do not have origin or header restrictions,
+# so browser-requests should be similarly permitted. (Though the API does not
+# require any custom headers, Ajax frameworks may automatically add headers
+# such as X-Requested-By to requests.)
+Rails.configuration.middleware.use Rack::Cors do
+  allow do
+    origins "*"
+    resource "/api/*", :headers => :any, :methods => [:get, :post, :put, :delete]
+  end
+end