Sha256: 9cc04cf7b8170d149ca432dd391bac199cbf50f5e1330681f268e155c07d36ee

Contents?: true

Size: 1.41 KB

Versions: 5

Compression:

Stored size: 1.41 KB

Contents

require 'erb'

module Inferno
  module Web
    client_page = ERB.new(File.read(File.join(Inferno::Application.root, 'lib', 'inferno', 'apps', 'web',
                                              'index.html.erb'))).result

    Router = Hanami::Router.new(namespace: Inferno::Web::Controllers) do
      namespace 'api' do
        resources 'test_runs', only: [:create, :show, :destroy] do
          resources 'results', only: [:index]
        end

        resources 'test_sessions', only: [:create, :show] do
          resources 'results', only: [:index]
          resources 'session_data', only: [:index]
        end
        get 'test_sessions/:test_session_id/last_test_run',
            to: Inferno::Web::Controllers::TestSessions::LastTestRun,
            as: :last_test_run

        resources 'test_suites', only: [:index, :show]

        resources 'requests', only: [:show]
      end

      get '/', to: ->(_env) { [200, {}, [client_page]] }
      get '/test_sessions/:id', to: ->(_env) { [200, {}, [client_page]] }

      Inferno.routes.each do |route|
        cleaned_id = route[:suite].id.gsub(/[^a-zA-Z\d\-._~]/, '_')
        path = "/custom/#{cleaned_id}#{route[:path]}"
        Application['logger'].info("Registering custom route: #{path}")
        if route[:method] == :all
          mount route[:handler], at: path
        else
          send(route[:method], path, to: route[:handler])
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
inferno_core-0.1.3 lib/inferno/apps/web/router.rb
inferno_core-0.1.3.pre2 lib/inferno/apps/web/router.rb
inferno_core-0.1.3.pre lib/inferno/apps/web/router.rb
inferno_core-0.1.2 lib/inferno/apps/web/router.rb
inferno_core-0.1.2.pre lib/inferno/apps/web/router.rb