require 'middleware/metrics_middleware' require 'middleware/request_id_middleware' require 'middleware/json_parse_errors' require 'middleware/bad_multipart_form_data_sanitizer' module ZuoraConnect class Railtie < Rails::Railtie config.before_initialize do version = Rails.version if version >= "5.0.0" ::Rails.configuration.public_file_server.enabled = true elsif version >= "4.2.0" ::Rails.configuration.serve_static_files = true else ::Rails.configuration.serve_static_assets = true end ::Rails.configuration.action_dispatch.x_sendfile_header = nil end initializer "zuora_connect.configure_rails_initialization" do |app| app.middleware.insert_after Rack::Sendfile, ZuoraConnect::MetricsMiddleware app.middleware.insert_after ActionDispatch::RequestId, ZuoraConnect::RequestIdMiddleware app.middleware.insert_before Rack::Runtime, ZuoraConnect::BadMultipartFormDataSanitizer app.config.middleware.use ZuoraConnect::JsonParseErrors end if defined? Prometheus require 'rack' require 'prometheus/middleware/exporter' initializer "prometheus.configure_rails_initialization" do |app| app.middleware.insert_after ZuoraConnect::MetricsMiddleware, Prometheus::Middleware::Exporter, path: '/connect/internal/metrics' app.config.middleware.use Rack::Deflater, if: ->(env, *) { env['PATH_INFO'] == '/connect/internal/metrics' } end end end end