Farklı mücevherlerin sistemimde nasıl etkileşime girdiğinden dolayı, raylar üzerine monte edilmiş bir motorum var. Son zamanlarda bazı middleware işlevselliği sağlayan yeni bir gem üzerinde çalışmaya başladı. Böyle birBir Motorda Bir Motordan Middleware Nasıl Kullanılır
Sıralama:
BaseApp
\
Engine
\
NewMiddlewareEngine
# BaseApp/Gemfile
gem 'Engine'
# Engine/Gemfile
gem 'NewMiddlewareEngine'
# rake middleware output:
[email protected][BaseApp]$ bundle exec rake middleware
use Rack::Sendfile
use ActionDispatch::Static
use Rack::Lock
use #<ActiveSupport::Cache::Strategy::LocalCache::Middleware:0x6ebf30e1>
use Rack::Runtime
use Rack::MethodOverride
use ActionDispatch::RequestId
use Rails::Rack::Logger
use ActionDispatch::ShowExceptions
use ActionDispatch::DebugExceptions
use ActionDispatch::RemoteIp
use ActionDispatch::Reloader
use ActionDispatch::Callbacks
use ActiveRecord::Migration::CheckPending
use ActiveRecord::ConnectionAdapters::ConnectionManagement
use ActiveRecord::QueryCache
use ActionDispatch::Cookies
use ActionDispatch::Session::CookieStore
use ActionDispatch::Flash
use CatchJsonParseErrors
use ActionDispatch::ParamsParser
use Rack::Head
use Rack::ConditionalGet
use Rack::ETag
run BaseApp::Application.routes
Ancak, katman gösterilmesini NewMiddlewareEngine almak gibi olamaz. Bu montaj test ettik:
BaseApp
\
NewMiddlewareEngine
# BaseApp/Gemfile
gem 'NewMiddlewareEngine'
# rake middleware output:
[email protected][BaseApp]$ bundle exec rake middleware
use Rack::Sendfile
use ActionDispatch::Static
use Rack::Lock
use #<ActiveSupport::Cache::Strategy::LocalCache::Middleware:0x2f9795d8>
use Rack::Runtime
use Rack::MethodOverride
use ActionDispatch::RequestId
use Rails::Rack::Logger
use ActionDispatch::ShowExceptions
use ActionDispatch::DebugExceptions
use ActionDispatch::RemoteIp
use ActionDispatch::Reloader
use ActionDispatch::Callbacks
use ActiveRecord::Migration::CheckPending
use ActiveRecord::ConnectionAdapters::ConnectionManagement
use ActiveRecord::QueryCache
use ActionDispatch::Cookies
use ActionDispatch::Session::CookieStore
use ActionDispatch::Flash
use CatchJsonParseErrors
use ActionDispatch::ParamsParser
use Rack::Head
use Rack::ConditionalGet
use Rack::ETag
use NewMiddlewareEngine # Notice it mounts fine on it's own
run BaseApp::Application.routes
Ve:
BaseApp
\
Engine
# BaseApp/Gemfile
gem 'Engine'
# rake middleware output:
[email protected][BaseApp]$ bundle exec rake middleware
use Rack::Sendfile
use ActionDispatch::Static
use Rack::Lock
use #<ActiveSupport::Cache::Strategy::LocalCache::Middleware:0x6ebf30e1>
use Rack::Runtime
use Rack::MethodOverride
use ActionDispatch::RequestId
use Rails::Rack::Logger
use ActionDispatch::ShowExceptions
use ActionDispatch::DebugExceptions
use ActionDispatch::RemoteIp
use ActionDispatch::Reloader
use ActionDispatch::Callbacks
use ActiveRecord::Migration::CheckPending
use ActiveRecord::ConnectionAdapters::ConnectionManagement
use ActiveRecord::QueryCache
use ActionDispatch::Cookies
use ActionDispatch::Session::CookieStore
use ActionDispatch::Flash
use CatchJsonParseErrors
use ActionDispatch::ParamsParser
use Rack::Head
use Rack::ConditionalGet
use Rack::ETag
run BaseApp::Application.routes
çok iyi çalışıyor. Sorun, NewMiddlewareEngine 'Motor aracılığıyla' monte etmeye çalıştığım zamandır.
Böyle bir şeyi nasıl yapılandıracağını bilen var mı? Rails::Engine Edge API belgelerine
module MyMiddlewareEngine
class Railtie < Rails::Railtie
initializer "add_my_middleware_engine_route_middleware" do |app|
app.middleware.use 'MyMiddlewareEngine'
end
end
end
Evet, 'komisyon aracı yazılımının çıktısını sağlayabilirsiniz – Tawan
Evet, kesinlikle. Tüm 3 varyasyon için ara katman yazılımı güncellemesi ekledim. – SortingHat
Diğer motorun başlatıcısında 'config.middleware.use NewMiddlewareEngine' denediniz mi? Bu motorun başlatıcısı kesinlikle çalıştırılıyor, bu yüzden işe koyulması için kodu koymanız gereken yer olabilir. Bu uygulama kodunda herhangi bir değişiklik gerektirmemelidir. –