title: Sinatra rack middleware hijacks '/' root url
body: <p>I'm trying to use a Sinatra app as middleware in my Rails app.</p>
  
  <p>I've tested a basic Sinatra app in the <code>/lib</code> folder of the Rails app, <code>use</code>d the middleware and set a route. That worked fine.</p>
  
  <p>What I want to be able to do is extract the Sinatra app and include it as a gem. That way I can run the Sinatra app independently, or use it in multiple Rails apps.</p>
  
  <p><strong>Sinatra App</strong></p>
  
  <pre><code># myrackapp/lib/myrackapp.rb
  module Myrackapp
    class Application &lt; Sinatra::Base
  
      set :root, File.dirname(__FILE__)
  
      get "/" do
        "Rack Home"
      end
  
      get '/rackroute' do
        "Hello, Rack Page"
      end
  
      end
  end
  </code></pre>
  
  <p><code>Myrackapp</code> also has a <code>gemspec</code> – nothing interesting there, but I can post if necessary.</p>
  
  <p><strong>Rails App</strong></p>
  
  <pre><code># Gemfile
  gem 'myrackapp', path: "/Users/gareth/Code/myrackapp"
  </code></pre>
  
  <p>-</p>
  
  <pre><code># config/application.rb
  module Myrailsapp
    class Application &lt; Rails::Application
      ...
      config.middleware.use "Myrackapp::Application"
    end
  end
  </code></pre>
  
  <p>-</p>
  
  <pre><code># config.routes.rb
  root :to =&gt; 'pages#show', :id =&gt; 'home'
  mount Myrackapp::Application =&gt; "/rackapp"
  </code></pre>
  
  <p>Here's my <code>rake middleware</code> output:</p>
  
  <pre><code>    rake middleware
      use ActionDispatch::Static
      use Rack::Lock
      use #&lt;ActiveSupport::Cache::Strategy::LocalCache::Middleware:0x141ded4&gt;
      use Rack::Runtime
      use Rack::MethodOverride
      use ActionDispatch::RequestId
      use Rails::Rack::Logger
      use ActionDispatch::ShowExceptions
      use ActionDispatch::DebugExceptions
      use ActionDispatch::RemoteIp
      use ActionDispatch::Reloader
      use ActionDispatch::Callbacks
      use ActiveRecord::ConnectionAdapters::ConnectionManagement
      use ActiveRecord::QueryCache
      use ActionDispatch::Cookies
      use ActionDispatch::Session::CookieStore
      use ActionDispatch::Flash
      use ActionDispatch::ParamsParser
      use ActionDispatch::Head
      use Rack::ConditionalGet
      use Rack::ETag
      use ActionDispatch::BestStandardsSupport
      use Myrackapp::Application
      run Myrailsapp::Application.routes
  </code></pre>
  
  <p>When I go to <code>http://myapp.dev/rackapp</code> I get <code>Myrackapp</code>'s root path - correct behaviour</p>
  
  <p>When I go to <code>http://myapp.dev/rackapp/rackroute</code> I get <code>Myrackapp</code>'s <code>/rackroute</code> path - again, correct behaviour</p>
  
  <h2>The Problem</h2>
  
  <p>When I go to <code>http://myapp.dev</code> in the browser I get directed to the <code>Myrackapp</code>'s root path.</p>
  
  <p>When I included the Sinatra app directly in my Rails app visiting <code>http://myapp.dev</code> rendered the correct <code>pages#show</code> action.</p>
  
  <p>What can I do to get the Sinatra app to not hijack the root path of Rails?</p>