New Shopify Certification now available: Liquid Storefronts for Theme Developers

Documentation Error, Authentication

Shopify Expert
4843 60 546

There is a code block about setting up CORS with the Rails App.



## config/application.rb ##
Rails.application.config.middleware.insert_before(0, Rack::Cors) do
  allow do
    origins '*' # allow access to this api from any domain
    resource '*', # allow all origins access to all resources
      headers: ['authorization', 'content-type', 'context'], # restrict headers to relevant keys
      methods: [:post] # restrict the methods to only the ones expected to be used by the extension


If you drop this into a Rails App, it throws an error 


uninitialized constant Rack::Cors (NameError)

Rails.application.config.middleware.insert_before(0, Rack::Cors) do


Custom Shopify Apps built just for you!
Reply 1 (1)
Shopify Partner
3 1 1

Make sure you add the `rack_cors` gem to your app. Add this to your gemfile:


gem 'rack-cors'

Learn more here: