cyu / rack-cors

Rack Middleware for handling Cross-Origin Resource Sharing (CORS), which makes cross-origin AJAX possible.
MIT License
3.26k stars 263 forks source link

Rack::Cors not getting inserted in rails middleware stack #229

Closed nimmolo closed 2 years ago

nimmolo commented 2 years ago

Have restarted the server multiple times... What in the world could be causing this?

At first I thought i didn't set the origin right, but then i realized Rack::Cors wasn't even in the mix.

Rails 5.2.6 Ruby 2.6.6

# Gemfile.lock
    rack-cors (1.1.1)
      rack (>= 2.0.0)
# config/cors.rb
Rails.application.config.middleware.insert_before(0, Rack::Cors) do
  allow do
    origins "http://localhost:3001"
    resource "/graphql", headers: :any, methods: [:get, :post, :patch, :put]
  end
end

Does Rails.application.config maybe need to be replaced with TheNameOfMyRails::Application.config? It didn't change anything when i tried it. No matter what i've done, Rack::Sendfile is still tops:

rails middleware

use Rack::Sendfile
use ActionDispatch::Static
use ActionDispatch::Executor
use ActiveSupport::Cache::Strategy::LocalCache::Middleware
use Rack::Runtime
use Rack::MethodOverride
use ActionDispatch::RequestId
use ActionDispatch::RemoteIp
use Rails::Rack::Logger
use ActionDispatch::ShowExceptions
use WebConsole::Middleware
use ActionDispatch::DebugExceptions
use ActionDispatch::Reloader
use ActionDispatch::Callbacks
use ActiveRecord::Migration::CheckPending
use ActionDispatch::Cookies
use ActionDispatch::Session::CookieStore
use ActionDispatch::Flash
use ActionDispatch::ContentSecurityPolicy::Middleware
use Rack::Head
use Rack::ConditionalGet
use Rack::ETag
use Rack::TempfileReaper
cyu commented 2 years ago

@nimmolo You want to put this file under config/initializers

nimmolo commented 2 years ago

Word! Thanks

On Oct 29, 2021, at 10:11 PM, Calvin Yu @.***> wrote:

@nimmolo You want to put this file under config/initializers

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.