lib/rhoconnect/server.rb in rhoconnect-3.1.2 vs lib/rhoconnect/server.rb in rhoconnect-3.2.0.beta1

- old
+ new

@@ -1,11 +1,10 @@ $:.unshift File.join(File.dirname(__FILE__),'..') require 'sinatra/base' require 'erb' require 'json' require 'fileutils' -#require 'rack/contrib' require 'rhoconnect' require 'rhoconnect/x_domain_session_wrapper' require 'rhoconnect/body_content_type_parser' require 'rhoconnect/cors' @@ -18,13 +17,10 @@ @error_code = error_code end end class Server < Sinatra::Base - libdir = File.dirname(File.expand_path(__FILE__)) - set :views, "#{libdir}/server/views" - set :public_folder, "#{libdir}/server/public" set :static, true set :stats, false # default secret @secret = '<changeme>' @@ -198,18 +194,42 @@ throw :halt, [422, "No API token provided"] end end end + private + def self._use_async_framework + return false if settings.respond_to?(:use_async_model) and settings.use_async_model == false + return false if @dispatch_framework_initialized + + @dispatch_framework_initialized ||=true + if RUBY_VERSION =~ /1.9/ and not defined?(JRUBY_VERSION) + require 'rhoconnect/async' + register Rhoconnect::Synchrony + helpers Rhoconnect::AsyncHelpers + else + settings.use_async_model = false + end + end + def self.new + # by default, enable this feature + if not settings.respond_to?(:use_async_model) or settings.use_async_model != false + set :use_async_model, true + end + # this must be called first - because + # it redefines some of the middleware + Rhoconnect::Server._use_async_framework + if settings.respond_to?(:stats) and settings.send(:stats) == true Rhoconnect.stats = true else Rhoconnect::Server.disable :stats Rhoconnect.stats = false end settings.use_middleware + super end def initialize # Whine about default session secret @@ -220,28 +240,28 @@ Rhoconnect.log "Rhoconnect Server v#{Rhoconnect::VERSION} started..." before do cache_control :no_cache headers({'pragma'=>'no-cache'}) - + if params[:version] and params[:version].to_i < 3 throw :halt, [404, "Server supports version 3 or higher of the protocol."] end end - + + get '/' do + redirect "/console/" + end + %w[get post].each do |verb| send(verb, "/*application*") do unless request_action == 'clientlogin' throw :halt, [401, "Not authenticated"] if login_required end pass end end - - get '/' do - erb :index - end - + # old routes post '/login' do mark_deprecated_call_and_reroute(:login, :admin, self, params) end get '/application' do