In my Rails API I have this code in cors.rb
Rails.application.config.middleware.insert_before 0, Rack::Cors do
allow do
origins 'example.com', 'api_dot_example.com'
resource '*',
headers: :any,
methods: %i[get post put patch delete options head],
expose: [:Authorization, 'Access-Control-Allow-Origin']
end
end
In the production.rb I try to define mailer setting like:
config.action_mailer.smtp_settings = {
ssl: true,
address: Rails.application.credentials.mail['address'],
port: Rails.application.credentials.mail['port'],
domain: Rails.application.credentials.mail['domain'],
authentication: :login,
user_name: Rails.application.credentials.mail['user_name'],
password: Rails.application.credentials.mail['password']
}
# config.action_mailer.smtp_settings = {
# ssl: true,
# address: 'example.com',
# port: 465,
# domain: 'example.com',
# authentication: :login,
# user_name: '[email protected]',
# password: 'fake_pass'
# }
When I hard-code the settings (like the comments in the code above), everything works. But if I try to retrieve the setting from rails credentials I get a CORS ERRORS:
OPTIONS api_dot_example_dot_com/login CORS Missing Allow Origin
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at api_dot_example_dot_com/login. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). Status code: 500.
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at api_dot_example_dot_com/login. (Reason: CORS request did not succeed). Status code: (null).
Can anyone please explain why this is happening?
1