New Shopify Certification now available: Liquid Storefronts for Theme Developers

Documentation Error, Authentication

HunkyBill
Shopify Expert
4843 60 546

https://shopify.dev/apps/subscriptions/app-extensions/authenticate

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
  end
end

 

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! hunkybill@gmail.com http://www.resistorsoftware.com
Reply 1 (1)
scottshop
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: https://github.com/cyu/rack-cors