Sha256: 0085e8823631ebdb617a0154fb25a51706e441e45c19482743d53f9440c1099c

Contents?: true

Size: 1.85 KB

Versions: 4

Compression:

Stored size: 1.85 KB

Contents

#TODO write RDoc
require 'fileutils'
require 'sinatra'
require "sinatra/json"
require 'securerandom'
require 'json'
#require 'net/http' #TODO not needed as calling other services is done in Utter Domain Extensions, Net::HTTP.get('example.com', '/index.html') # => String

module Utter
  module Internals
    class Service < Sinatra::Base

      run! if app_file == $0

      # if cross_origin is required\loaded then make register Sinatra::CrossOrigin 
      # And 
      #register Sinatra::CrossOrigin

      #TODO 	set a flag to disable this in production for security
      #		this helps testing APIs on localmachines as CORS fucks developers time.
      # 	But not recommended to be set while in production enviroments
      before do
	response.headers["Access-Control-Allow-Origin"] = "*"
      end
      #	response.headers["Access-Control-Allow-Methods"] = "*"
      #	#response.headers["Access-Control-Allow-Methods"] = "POST"
      #	p response.headers.inspect
      #      end
      #
      # Makes sure that any response Utter gives back is in JSON format
      #TODO check if streaming needs a different class if this mechanism doesn't work with it
      def route(verb, path, options = {}, &block)
	super
	signature.to_json # regular json
	#json signature #NOTE we can use regular json or sinatra/json'
      end

      configure do 
	set :server, :puma  #if development make it shotgun, if production make it puma

	#NOTE http://www.sinatrarb.com/contrib/json.html
	set :json_encoder, :to_json #uses sinatra/json
	set :json_content_type, :js #uses sinatra/json
      end

    end

    #class Public::Microservice < Utter::Microservice; end
    #class Private::Microservice < Utter::Microservice
    #TODO do somthing here to make it secure via some mechanism!
    # as we don't do websites, we striclty focus on APIs we can use HTTP basic auth to make it secure!?
    #end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
utter-1.9.0 lib/utter/service.rb
utter-1.8.0 lib/utter/service.rb
utter-1.7.0 lib/utter/service.rb
utter-1.6.0 lib/utter/service.rb