# use PathPrefix Middleware if :path_prefix is set in Merb::Config
if prefix = ::Merb::Config[:path_prefix]
  use Merb::Rack::PathPrefix, prefix
end

# comment this out if you are running merb behind a load balancer
# that serves static files

require 'multistatic'

use Merb::Rack::MultiStatic, Domain.all if Merb::Config[:multidomain]
use Merb::Rack::Static, Merb.dir_for(:public)

# this is our main merb application
run Merb::Rack::Application.new
# use PathPrefix Middleware if :path_prefix is set in Merb::Config
if prefix = ::Merb::Config[:path_prefix]
  use Merb::Rack::PathPrefix, prefix
end

# comment this out if you are running merb behind a load balancer
# that serves static files

require 'multistatic'

if Domain.storage_exists? && Merb::Config[:multidomain]
  use Merb::Rack::MultiStatic, Domain.all
end
use Merb::Rack::Static, Merb.dir_for(:public)

# this is our main merb application
run Merb::Rack::Application.new
Make sure app load does not fail for lack of Domain table
Make sure app load does not fail for lack of Domain table

Rake needs to successfully load the app before it will migrate the
database.  Whether or not this is the correct behavior is up for
debate, but in the mean time we will leave off serving multidomains
in the rack config file if there is no database table. This solves
the chicken-and-egg problem for `rake db:automigrate`.
