These three patches fix a few crucial things:
1/3 runs the server in development mode by default for better stacktraces 2/3 fixes another Sinatra 0.9.4 incompatibility 3/3 makes requests with extensions (/api/flavors.xml) work under Sinatra 0.9.4
David
From: David Lutterkort lutter@redhat.com
* do not hardcode production mode by default * set configuration at the top of server.rb * in dev mode, make stdout and stderr synchronous --- server/libexec/config.ru | 8 -------- server/libexec/server.rb | 8 ++++++++ 2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/server/libexec/config.ru b/server/libexec/config.ru index 5ca4fbb..6d37a5f 100644 --- a/server/libexec/config.ru +++ b/server/libexec/config.ru @@ -1,13 +1,5 @@ require 'sinatra' require 'rubygems'
-set :environment => :production -set :raise_errors => false -set :run => false - -#log = File.new("log/deltacloud.log", "a+") -#STDOUT.reopen(log) -#STDERR.reopen(log) - require 'server.rb' run Sinatra::Application diff --git a/server/libexec/server.rb b/server/libexec/server.rb index 8185eff..2ebe277 100644 --- a/server/libexec/server.rb +++ b/server/libexec/server.rb @@ -12,6 +12,14 @@ require 'sinatra/rabbit' require 'sinatra/validation' require 'sinatra/lazy_auth'
+set :raise_errors => false + +configure :development do + # So we can just use puts for logging + $stdout.sync = true + $stderr.sync = true +end + DRIVER=ENV['API_DRIVER'] ? ENV['API_DRIVER'].to_sym : :mock
# You could use $API_HOST environment variable to change your hostname to
From: David Lutterkort lutter@redhat.com
With Sinatra 0.9.4, there's no Sinatra::mime_type; use the wrapper method from Helpers. --- server/libexec/lib/sinatra/respond_to.rb | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/server/libexec/lib/sinatra/respond_to.rb b/server/libexec/lib/sinatra/respond_to.rb index 8e54bda..3365351 100644 --- a/server/libexec/lib/sinatra/respond_to.rb +++ b/server/libexec/lib/sinatra/respond_to.rb @@ -56,7 +56,7 @@ module Sinatra ext = options.default_content end if ext - @mime_types = [ mime_type(ext) ] + @mime_types = [ Helpers::mime_type(ext) ] format ext end end
From: David Lutterkort lutter@redhat.com
* server.rb: register RespondTo with the application, not Sinatra::Base --- server/libexec/server.rb | 4 +--- 1 files changed, 1 insertions(+), 3 deletions(-)
diff --git a/server/libexec/server.rb b/server/libexec/server.rb index 2ebe277..3ae161e 100644 --- a/server/libexec/server.rb +++ b/server/libexec/server.rb @@ -28,9 +28,7 @@ HOSTNAME=ENV['API_HOST'] ? ENV['API_HOST'] : nil
Rack::Mime::MIME_TYPES.merge!({ ".gv" => "text/plain" })
-module Sinatra - register Sinatra::RespondTo -end +Sinatra::Application.register Sinatra::RespondTo
# Common actions #
On 22/02/10 15:17 -0800, lutter@redhat.com wrote:
These three patches fix a few crucial things:
1/3 runs the server in development mode by default for better stacktraces 2/3 fixes another Sinatra 0.9.4 incompatibility 3/3 makes requests with extensions (/api/flavors.xml) work under Sinatra 0.9.4
These patches looks great. ACK
Btw. do we will offer possibility to run Sinatra in production mode in future ? (Maybe as command line parameter as Rails do this).
On Tue, 2010-02-23 at 13:30 +0100, Michal Fojtik wrote:
On 22/02/10 15:17 -0800, lutter@redhat.com wrote:
These three patches fix a few crucial things:
1/3 runs the server in development mode by default for better stacktraces 2/3 fixes another Sinatra 0.9.4 incompatibility 3/3 makes requests with extensions (/api/flavors.xml) work under Sinatra 0.9.4
These patches looks great. ACK
Btw. do we will offer possibility to run Sinatra in production mode in future ? (Maybe as command line parameter as Rails do this).
Good catch .. I thought that happened already from the RACK_ENV environment variable; but thin helpfully overrides it. I just added this patch, too, and pushed the whole series:
From d798c901316216ca0eba9f428d61af75905381ff Mon Sep 17 00:00:00 2001
From: David Lutterkort lutter@redhat.com Date: Tue, 23 Feb 2010 11:07:19 -0800 Subject: [PATCH core 4/4] * bin/deltacloudd: allow setting environment with RACK_ENV
--- server/bin/deltacloudd | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/server/bin/deltacloudd b/server/bin/deltacloudd index 5d5a861..ecdda74 100755 --- a/server/bin/deltacloudd +++ b/server/bin/deltacloudd @@ -58,10 +58,12 @@ if [ -z "$rerun" ]; then exit 1 fi
+[ -z "$RACK_ENV" ] && RACK_ENV=development + export API_DRIVER export API_HOST export API_PORT
echo "Starting Deltacloud API :: '$API_DRIVER' driver :: http://$API_HOST:$API_PORT/api"
-rerun "thin start --debug --port=$API_PORT --address=$API_HOST -c '$topdir/libexec' -R config.ru" +rerun "thin start --debug --port=$API_PORT --address=$API_HOST -e $RACK_ENV -c '$topdir/libexec' -R config.ru"
deltacloud-devel@lists.fedorahosted.org