diff --git a/app/middlewares/wopi_method_override.rb b/app/middlewares/wopi_method_override.rb new file mode 100644 index 000000000..e30a5c75b --- /dev/null +++ b/app/middlewares/wopi_method_override.rb @@ -0,0 +1,19 @@ +# When WOPI performs calls onto sciNote WOPI subdomain REST endpoints +# Rack::MethodOverride MUST be omitted because it crashes the requests +# due to trying to parse body of the requests +class WopiMethodOverride + def initialize(app) + @app = app + end + + def call(env) + app = @app + + unless WopiSubdomain.matches?(ActionDispatch::Request.new(env)) + # Use the wrapped Rack::MethodOverride middleware + app = Rack::MethodOverride.new(@app) + end + + app.call(env) + end +end \ No newline at end of file diff --git a/config/application.rb b/config/application.rb index 129ba8e4c..4442591d6 100644 --- a/config/application.rb +++ b/config/application.rb @@ -15,6 +15,10 @@ module Scinote # Application configuration should go into files in config/initializers # -- all .rb files in that directory are automatically loaded. + # Swap the Rack::MethodOverride with a wrapped middleware for WOPI handling + require_relative '../app/middlewares/wopi_method_override' + config.middleware.swap Rack::MethodOverride, WopiMethodOverride + # Load all model concerns, including subfolders config.autoload_paths += Dir["#{Rails.root}/app/models/concerns/**/*.rb"]