Sha256: 99bdb790bc2f58a6a8b966b4685714c2c95b6eb8462bcaf3f639e98e53b178f6

Contents?: true

Size: 894 Bytes

Versions: 1

Compression:

Stored size: 894 Bytes

Contents

require 'sinatra'

module Kosmos
  module Web
    class App < Sinatra::Application
      set server: 'thin', connection: nil

      get '/' do
        send_file(File.join(settings.public_folder, 'index.html'))
      end

      get '/stream', provides: 'text/event-stream' do
        stream :keep_open do |out|
          settings.connection = out
        end
      end

      post '/' do
        Kosmos.configure do |config|
          config.output_method = Proc.new do |str|
            str.split("\n").each do |line|
              settings.connection << "data: #{line}\n\n"
            end
          end
        end

        kosmos_params = params[:params].split(' ')
        kosmos_command = %w(init install uninstall list).find do |command|
          command == params[:command]
        end

        UserInterface.send(kosmos_command, kosmos_params)

        204
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
kosmos-0.0.5 lib/kosmos/web/app.rb