running rails 6.1.1 development server on http://localhost:3000 (via rails s)
react client on http://localhost:3001 (via yarn start)
I have tried the following
in gemfile, gem 'rack-cors' and bundle install
in config/intializers/cors.rb
Rails.application.config.middleware.insert_before 0, Rack::Cors do
allow do
origins '*'
resource '*',
headers: :any,
methods: [:get, :post, :put, :patch, :delete, :options, :head]
end
in application.rb
config.middleware.insert_before 0, Rack::Cors do
allow do
origins '*'
resource '*', :headers => :any, :methods => [:get, :post, :options]
end
end
example axios request from react js client
axios.post('http://localhost:3000/users', {user}, {withCredentials: true})
.then(response => {
...
})
.catch(error => console.log('api errors:', error))
};
also tried replacing localhost with 127.0.0.1, prepending http:// in config, but none of the solutions are working
response error says blocked by CORS policy
Access to XMLHttpRequest at 'http://localhost:3000/users' from origin 'http://localhost:3001' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
