Due to policies around Cross-Origin Resource Sharing (CORS), there is some additional configuration required in your API in order to allow our back end and front end applications to communicate with each other. We basically need to allow our API to accept requests from our front end application rather than blocking them for security reasons. It is the software development equivalent of stranger danger. We’ll talk more about CORS in module 3, so don’t worry about understanding the details of this configuration or the motivation behind it quite yet. If you’re curious, you can read more about it here.
[x] Uncomment in Gemfile
[x] Run bundle install
[x] Add the Following Code to config/initializers/cors.rb File
Rails.application.config.middleware.insert_before 0, Rack::Cors do
allow do
origins "localhost:5173"
Due to policies around Cross-Origin Resource Sharing (CORS), there is some additional configuration required in your API in order to allow our back end and front end applications to communicate with each other. We basically need to allow our API to accept requests from our front end application rather than blocking them for security reasons. It is the software development equivalent of stranger danger. We’ll talk more about CORS in module 3, so don’t worry about understanding the details of this configuration or the motivation behind it quite yet. If you’re curious, you can read more about it here.
bundle install
Rails.application.config.middleware.insert_before 0, Rack::Cors do allow do origins "localhost:5173"
end end
What’s happening here?