Sha256: 4e685179de552a62470bdf7d3a4efd4e8c1917b2f405f41261323410f2a6ee8d

Contents?: true

Size: 1.86 KB

Versions: 1

Compression:

Stored size: 1.86 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

1 entries across 1 versions & 1 rubygems

Version Path
utter-1.5.0 lib/utter/service.rb