Add special middleware for handling of Rails 5.1 WOPI errors

Closes SCI-2266.
This commit is contained in:
Luka Murn 2018-04-05 12:54:14 +02:00
parent 159078170a
commit 386ede0400
2 changed files with 23 additions and 0 deletions

View file

@ -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

View file

@ -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"]