Sha256: ead413ad491019cfd1a6eeac8ccc8cf09a787d8a9fe663ca810d97718b7e6c37

Contents?: true

Size: 1.26 KB

Versions: 48

Compression:

Stored size: 1.26 KB

Contents

# frozen_string_literal: true

module AppMap
  OpenStruct = Struct.new(:appmap)

  class Open < OpenStruct
    attr_reader :port

    def perform
      server = run_server
      open_browser
      server.kill
    end

    def page
      require 'rack/utils'
      <<~PAGE
      <!DOCTYPE html>
      <html>
      <head>
        <title>&hellip;</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <script type="text/javascript">
        function dosubmit() { document.forms[0].submit(); }
        </script>
      </head>
      <body onload="dosubmit();">
        <form action="https://app.land/scenario_uploads" method="POST" accept-charset="utf-8">
        <input type="hidden" name="data" value='#{Rack::Utils.escape_html appmap.to_json}'>
        </form>
      </body>
      </html>
      PAGE
    end

    def run_server
      require 'rack'
      Thread.new do
        Rack::Handler::WEBrick.run(
          lambda do |env|
            [200, { 'Content-Type' => 'text/html' }, [page]]
          end,
          :Port => 0
        ) do |server|
          @port = server.config[:Port]
        end
      end.tap do
        sleep 1.0
      end
    end

    def open_browser
      system 'open', "http://localhost:#{@port}"
      sleep 5.0
    end
  end
end

Version data entries

48 entries across 48 versions & 1 rubygems

Version Path
appmap-1.1.1 lib/appmap/open.rb
appmap-1.0.1 lib/appmap/open.rb
appmap-1.0.0 lib/appmap/open.rb
appmap-0.103.0 lib/appmap/open.rb
appmap-0.102.2 lib/appmap/open.rb
appmap-0.102.1 lib/appmap/open.rb
appmap-0.102.0 lib/appmap/open.rb
appmap-0.101.0 lib/appmap/open.rb
appmap-0.100.0 lib/appmap/open.rb
appmap-0.99.4 lib/appmap/open.rb
appmap-0.99.2 lib/appmap/open.rb
appmap-0.99.1 lib/appmap/open.rb
appmap-0.99.0 lib/appmap/open.rb
appmap-0.98.1 lib/appmap/open.rb
appmap-0.98.0 lib/appmap/open.rb
appmap-0.97.0 lib/appmap/open.rb
appmap-0.96.0 lib/appmap/open.rb
appmap-0.95.2 lib/appmap/open.rb
appmap-0.95.1 lib/appmap/open.rb
appmap-0.95.0 lib/appmap/open.rb