Questions and discussions about using the Shopify CLI and Shopify-built libraries.
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
^^^^^^
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