Sha256: 19deb64e83264043dc4f731f76ca53d6973642a7d9339fe8513aa4bf5bb64095

Contents?: true

Size: 845 Bytes

Versions: 5

Compression:

Stored size: 845 Bytes

Contents

# frozen_string_literal: true

require 'mkit/exceptions'

module MKIt
  class Server < Sinatra::Base
    set :default_content_type, :json
    set :dump_errors, true
    set :show_exceptions, false
    set :raise_errors, false
    set :sockets, []
    set :listeners, []

    before do
      api_key = request.env['HTTP_X_API_KEY']
      cfg = YAML.load_file(MKIt::Config.config_file)
      if cfg.nil? || cfg['mkit'].nil? || cfg['mkit']['clients'].nil? || !cfg['mkit']['clients'].map{|h| h['id']}.include?(api_key)
        error 401, 'Unauthorized - please add your client-id to authorized clients list'
      end
    end

    error MKIt::BaseException do |e|
      MKItLogger.debug e
      error e.error_code, e.message
    end

    error do |e|
      MKItLogger.debug e
      error 500, "Internal server error: #{e.message}"
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
mkit-0.9.0 lib/mkit/app/mkit_server.rb
mkit-0.8.0 lib/mkit/app/mkit_server.rb
mkit-0.7.2 lib/mkit/app/mkit_server.rb
mkit-0.7.1 lib/mkit/app/mkit_server.rb
mkit-0.7.0 lib/mkit/app/mkit_server.rb