You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by mf...@redhat.com on 2012/04/17 15:39:47 UTC

[PATCH core 08/32] Core: Fixed config.ru file to spawn a modular application

From: Michal Fojtik <mf...@redhat.com>


Signed-off-by: Michal fojtik <mf...@redhat.com>
---
 server/config.ru |   44 ++++++++++++++++++++++++++++++++++++++------
 1 file changed, 38 insertions(+), 6 deletions(-)

diff --git a/server/config.ru b/server/config.ru
index a1f9efd..f17de43 100644
--- a/server/config.ru
+++ b/server/config.ru
@@ -14,14 +14,46 @@
 # License for the specific language governing permissions and limitations
 # under the License.
 
-require 'rubygems'
+# The default URL prefix (where to mount Deltacloud API)
 
-$top_srcdir ||= File::expand_path(File.dirname(__FILE__))
+# The default driver is 'mock'
+ENV['API_DRIVER'] ||= 'mock'
 
-$:.unshift File.join($top_srcdir, 'lib')
+# Set the API frontend use ('cimi' or 'deltacloud', default is 'deltacloud')
+ENV['API_FRONTEND'] ||= 'deltacloud'
 
-server_dir = ENV['API_FRONTEND'] == 'cimi' ? 'cimi' : 'deltacloud'
+# We need to set different API version and entrypoint location
+if ENV['API_FRONTEND'] == 'deltacloud'
+  API_VERSION = "9.9.9"
+  API_ROOT_URL = "/api"
+elsif ENV['API_FRONTEND'] == 'cimi'
+  API_VERSION = "1.0.0"
+  API_ROOT_URL = "/cloudEntryPoint"
+end
 
-load File.join($top_srcdir, 'lib', server_dir, 'server.rb')
+#begin
+  require File.join(File.dirname(__FILE__), 'lib', ENV['API_FRONTEND'], 'server.rb')
+#rescue LoadError => e
+#  puts "[ERROR] The specified frontend (#{ENV['API_FRONTEND']}) not supported (#{e.message})"
+#  exit 1
+#end
 
-run Sinatra::Application
+if self.respond_to? :map
+  map "/" do
+    class IndexEntrypoint < Sinatra::Base
+      get "/" do
+        redirect API_ROOT_URL, 301
+      end
+    end
+    run IndexEntrypoint
+  end
+
+  map API_ROOT_URL do
+    use Rack::Static, :urls => ["/stylesheets", "/javascripts"], :root => "public"
+    use Rack::Session::Cookie
+    case ENV['API_FRONTEND']
+      when 'deltacloud' then run Rack::Cascade.new([Deltacloud::API])
+      when 'cimi' then run Rack::Cascade.new([CIMI::API])
+    end
+  end
+end
-- 
1.7.10