異なるシステムが私のシステムでどのようにやりとりされるかによって、エンジンがレールアプリケーションにマウントされています。私は最近、いくつかのミドルウェア機能を提供する新しい宝石の開発に着手しました。このようなのエンジンのエンジンからミドルウェアを使用する方法
並べ替え:
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
しかし、私はNewMiddlewareEngineはミドルウェアに表示するように見えることはできません。
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
そして:
両方が正常に動作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
私はこれを取り付けテストしてみました。問題は、Engineを通じてNewMiddlewareEngineをマウントしようとするときです。
誰もこのような設定方法を知っていますか?
はここMyMiddlewareEngineは取り付けています:
module MyMiddlewareEngine
class Railtie < Rails::Railtie
initializer "add_my_middleware_engine_route_middleware" do |app|
app.middleware.use 'MyMiddlewareEngine'
end
end
end
'rake middleware'の出力を提供できますか – Tawan
ええ、確かです。 3つすべてのバリエーションのミドルウェア出力を含めるように更新しました。 – SortingHat
他のエンジンのイニシャライザで 'config.middleware.use NewMiddlewareEngine'を試しましたか?そのエンジンのイニシャライザは確実に動作しているので、それが動作するためのコードを置く必要があります。これにより、アプリケーションコードを変更する必要はありません。 –