diff --git a/lib/inferno/apps/web/controllers/controller.rb b/lib/inferno/apps/web/controllers/controller.rb index b606a9971..5ed8fc9b6 100644 --- a/lib/inferno/apps/web/controllers/controller.rb +++ b/lib/inferno/apps/web/controllers/controller.rb @@ -20,7 +20,9 @@ def self.inherited(subclass) # Hanami Controller 2.0.0 removes the ability to set a default # Content-Type response header, so set it manually if it hasn't been # set. - subclass.after { |_req, res| res.format = :json if res.format == :all && res.body&.first&.first == '{' } + subclass.after do |_req, res| + res.format = :json if res.format == :all + end end def self.resource_name diff --git a/lib/inferno/apps/web/router.rb b/lib/inferno/apps/web/router.rb index 6ae96939b..6b118cff2 100644 --- a/lib/inferno/apps/web/router.rb +++ b/lib/inferno/apps/web/router.rb @@ -4,8 +4,12 @@ module Inferno module Web - client_page = ERB.new(File.read(File.join(Inferno::Application.root, 'lib', 'inferno', 'apps', 'web', - 'index.html.erb'))).result + client_page = ERB.new( + File.read( + File.join(Inferno::Application.root, 'lib', 'inferno', 'apps', 'web', 'index.html.erb') + ) + ).result + CLIENT_PAGE_RESPONSE = ->(_env) { [200, { 'Content-Type' => 'text/html' }, [client_page]] } base_path = Application['base_path']&.delete_prefix('/') @@ -47,12 +51,14 @@ module Web get '/requests/:id', to: Inferno::Web::Controllers::Requests::Show, as: :requests_show - get '/version', to: ->(_env) { [200, {}, [{ 'version' => Inferno::VERSION.to_s }.to_json]] }, as: :version + get '/version', to: lambda { |_env| + [200, { 'Content-Type' => 'application/json' }, [{ 'version' => Inferno::VERSION.to_s }.to_json]] + }, as: :version end # Should not need Content-Type header but GitHub Codespaces will not work without them. # This could be investigated and likely removed if addressed properly elsewhere. - get '/', to: ->(_env) { [200, { 'Content-Type' => 'text/html' }, [client_page]] } + get '/', to: CLIENT_PAGE_RESPONSE get '/jwks.json', to: lambda { |_env| [200, { 'Content-Type' => 'application/json' }, [Inferno::JWKS.jwks_json]] }, as: :jwks @@ -70,7 +76,7 @@ module Web Inferno::Repositories::TestSuites.all.map { |suite| "/#{suite.id}" }.each do |suite_path| Application['logger'].info("Registering suite route: #{suite_path}") - get suite_path, to: ->(_env) { [200, {}, [client_page]] } + get suite_path, to: CLIENT_PAGE_RESPONSE end get '/test_sessions/:id', to: Inferno::Web::Controllers::TestSessions::ClientShow, as: :client_session_show @@ -83,7 +89,7 @@ module Web if base_path.present? Hanami::Router.new do scope("#{base_path}/") do - get '/', to: ->(_env) { [200, { 'Content-Type' => 'text/html' }, [client_page]] } + get '/', to: CLIENT_PAGE_RESPONSE end scope(base_path, &route_block) end