CCirbo / Little_Shop

1 stars 2 forks source link

Connect to FE - Add`rack-cors` to Gemfile #5

Closed TDManning closed 4 weeks ago

TDManning commented 4 weeks ago

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.

Rails.application.config.middleware.insert_before 0, Rack::Cors do allow do origins "localhost:5173"

resource "*",
  headers: :any,
  methods: [:get, :post, :put, :patch, :delete, :options, :head]

end end

What’s happening here?

CCirbo commented 4 weeks ago

Finished and PR created and merged.