lib/hippo/api/root.rb in hippo-fw-0.9.1 vs lib/hippo/api/root.rb in hippo-fw-0.9.2
- old
+ new
@@ -1,70 +1,69 @@
require 'sinatra'
require 'oj'
require 'rack/protection'
require 'rack/cors'
-require_relative "../access/authentication_provider"
+module Hippo::API
+ class Root < Sinatra::Application
+ CORS_PATHS = {}
-module Hippo
- module API
- class Root < Sinatra::Application
- CORS_PATHS = {}
+ Hippo.config.get(:environment) do | env |
+ set :environment, env
+ end
+ helpers RequestWrapper
+ helpers HelperMethods
+ helpers FormattedReply
+ use TenantDomainRouter
+ use Rack::Session::Cookie,
+ :key => 'rack.session',
+ :secret => Hippo.config.session_secret_key_base
+ not_found do
+ Oj.dump({ message: "endpoint not found", success: false })
+ end
- Hippo.config.get(:environment) do | env |
- set :environment, env
- end
- helpers RequestWrapper
- helpers HelperMethods
- helpers FormattedReply
+ error ActiveRecord::RecordNotFound do
+ halt 404, error_as_json
+ end
- use Rack::Session::Cookie,
- :key => 'rack.session',
- :secret => Hippo.config.session_secret_key_base
- not_found do
- Oj.dump({ message: "endpoint not found", success: false })
- end
- error ActiveRecord::RecordNotFound do
- halt 404, error_as_json
- end
- error do
- error_as_json
- end
+ error do
+ error_as_json
+ end
- configure do
- set :show_exceptions, false
- require_relative 'routing'
- Hippo::Configuration.apply
- Extensions.load_controlling_config
+ configure do
+ set :show_exceptions, false
+ Hippo::Configuration.apply
+ Hippo::Extensions.load_controlling_config
+ set :views, Hippo::Extensions.controlling.root_path.join('views')
+ set :webpack, Hippo::Webpack.new
+ webpack.start
+ require_relative './routing'
+ Cable.configure
+ cors_resources = []
+ if CORS_PATHS.any?
+ use Rack::Cors,
+ debug: !Hippo.env.production?,
+ logger: Hippo.logger do
- set :views, Extensions.controlling.root_path.join('views')
-
- require_relative './default_routes'
- API::Cable.configure
- end
-
- configure do
- cors_resources = []
- if API::Root::CORS_PATHS.any?
- use Rack::Cors, debug: !Hippo.env.production?, logger: Hippo.logger do
- API::Root::CORS_PATHS.each do | path, options |
- allow do
- cors_resources.push Rack::Cors::Resource.new('', path)
- origins options[:origins]
- resource path,
- :methods => options[:methods].map(&:to_sym) + [:options],
- :headers => :any
- end
+ CORS_PATHS.each do | path, options |
+ allow do
+ cors_resources.push Rack::Cors::Resource.new('', path)
+ origins options[:origins]
+ resource path,
+ :methods => options[:methods].map(&:to_sym) + [:options],
+ :headers => :any
end
-
end
end
- # use Rack::Protection, allow_if: -> (env) {
- # path = env['PATH_INFO']
- # cors_resources.any?{|r| r.matches_path?(path) }
- # }
end
+
+ use Rack::Protection, allow_if: -> (env) {
+ path = env['PATH_INFO']
+ cors_resources.any?{|r| r.matches_path?(path) }
+ }
end
+
end
+
end