-
Notifications
You must be signed in to change notification settings - Fork 263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
how can i add multiple origins in rack-cors #178
Comments
As specified in #131 you'll have to add multiple allowed_headers = %i(get post put patch delete options head)
allow do
origins 'http://localhost:3000'
resource '*', headers: :any, methods: allowed_headers
end
allow do
origins 'http://localhost:4000'
resource '*', headers: :any, methods: allowed_headers
end |
This would be a good addition to the README! |
The original post is passing a single string with a comma separated list to
that is incorrect. https://github.com/cyu/rack-cors#rack-configuration use Rack::Cors do
allow do
origins 'localhost:3000', '127.0.0.1:3000',
/\Ahttp:\/\/192\.168\.0\.\d{1,3}(:\d+)?\z/
# regular expressions can be used here The code loops through the origins and checks each for a match rack-cors/lib/rack/cors/resources.rb Lines 42 to 50 in dbea904
So you should be passing
(passing 2 strings as opposed to passing 1 comma separated string) |
How can we pass an environment variable to The environment variable must be a string so separate the domains by a whitespace.
Yields: This won't work because it is a string instead of a comma separated list. One way to get this to work is to loop through the values similar to Cam's answer |
@cickes try this:
|
I'm doing some issue gardening 🌱🌿 🌷 and came upon this issue. Since it's quite old I just wanted to ask if this is still relevant? If it isn't, maybe we can close this issue? By closing some old issues we reduce the list of open issues to a more manageable set. |
Rails.application.config.middleware.insert_before 0, Rack::Cors do
allow do
origins 'http://localhost:3000, http://localhost:4000'
resource '*',
headers: :any,
methods: [:get, :post, :put, :patch, :delete, :options, :head]
end
end
The text was updated successfully, but these errors were encountered: