Question

I was wondering which could be a better way of mounting different apps for ruby . I have 2 sinatra apps and one rails app .

One way is to use rails as base and mount the sinatra apps using the routes.rb (within rails)

RailsApp::Application.routes.draw do
  mount SinatraApp1, :at => "/url1"
  mount SinatraApp2, :at => "/url2"
  # rest of the rail routes
end

This way both the sinatra apps are in rails.

Other way is to use rackup to mount all three using config.ru (all three apps in parallel)

map "/" do
  run RailsApp::Application
end

map "/url1" do
  run SinatraApp1
end

map "/url2" do
  run SinatraApp2
end

I am not able to find the advantages of one over the other or which method is better for what reason.

Was it helpful?

Solution

Interesting there is any significant difference apart from the fact that in the latter part(application mounted using rackup)

any requests to

/url1

/url2

would be server directly from the mounted rack application without actually passing the request in the middleware stack of rails and then detect valid rack application for the given mounted path .

Which would happen in first part where your sinatra application is mounted inside Rails defined in routes.rb of your file

So I your are trying to mount your sinatra application in routes.rb instead of config.ru then consider the fact that your request would be passed all along rails middleware stack where routing middleware detect the appropriate path as passed the request to desired sinatra application

A Simple check You can do for this is try hitting your path i.e /url1 or /url2 in both the technique and you would see sinatra application routes.rb would log the request in your rails application whereas the other one would not

Hope this help

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top