Subdomain routing in Sinatra

Cushion serves the web app from the my. subdomain and the signup routes from the get. subdomain. I’ve always relied on Sinatra::Namespace to scope the routes, so the root path (/) under get.cushionapp.com would go to the right place, while the root pat…


This content originally appeared on Jonnie Hallman (@destroytoday) and was authored by Jonnie Hallman (@destroytoday)

Cushion serves the web app from the my. subdomain and the signup routes from the get. subdomain. I’ve always relied on Sinatra::Namespace to scope the routes, so the root path (/) under get.cushionapp.com would go to the right place, while the root path under my.cushionapp.com would go to its right place. I recently discovered that Sinatra has been cascading through the modular apps for these routes and triggering the 404 route for each modular app that shares the same route you’re visiting. Not great, and explains why Cushion’s route requests have felt slower than they should be. While I do use Sinatra::Router to mount all the modular apps, I didn’t realize it supports custom conditionals. With this ability, I was able to refactor the subdomain scoping with a custom conditional method, subdomain, that checks the subdomain of the request. Instead of using:

namespace host_name: /^get./ do
  mount MyApp
end

...I mount the modular app inside a subdomain block, like this:

subdomain :get do
  mount MyApp
end

Reply via email


This content originally appeared on Jonnie Hallman (@destroytoday) and was authored by Jonnie Hallman (@destroytoday)


Print Share Comment Cite Upload Translate Updates
APA

Jonnie Hallman (@destroytoday) | Sciencx (2020-06-13T10:36:00+00:00) Subdomain routing in Sinatra. Retrieved from https://www.scien.cx/2020/06/13/subdomain-routing-in-sinatra/

MLA
" » Subdomain routing in Sinatra." Jonnie Hallman (@destroytoday) | Sciencx - Saturday June 13, 2020, https://www.scien.cx/2020/06/13/subdomain-routing-in-sinatra/
HARVARD
Jonnie Hallman (@destroytoday) | Sciencx Saturday June 13, 2020 » Subdomain routing in Sinatra., viewed ,<https://www.scien.cx/2020/06/13/subdomain-routing-in-sinatra/>
VANCOUVER
Jonnie Hallman (@destroytoday) | Sciencx - » Subdomain routing in Sinatra. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2020/06/13/subdomain-routing-in-sinatra/
CHICAGO
" » Subdomain routing in Sinatra." Jonnie Hallman (@destroytoday) | Sciencx - Accessed . https://www.scien.cx/2020/06/13/subdomain-routing-in-sinatra/
IEEE
" » Subdomain routing in Sinatra." Jonnie Hallman (@destroytoday) | Sciencx [Online]. Available: https://www.scien.cx/2020/06/13/subdomain-routing-in-sinatra/. [Accessed: ]
rf:citation
» Subdomain routing in Sinatra | Jonnie Hallman (@destroytoday) | Sciencx | https://www.scien.cx/2020/06/13/subdomain-routing-in-sinatra/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.