Mount Rack Apps

Jets Routing supports mounting Rack applications. Example:

config/routes.rb

Jets.application.routes.draw do
  mount GrapeApp, at: 'grape'     # app/racks/grape_app
  mount SinatraApp, at: 'sinatra' # app/racks/sinatra_app
  mount RackApp, at: 'rack'  # app/racks/rack_app
end

Many Ruby Web frameworks are Rack compatible like Sinatra, Grape, Padrino, Hanami, and more. The mount ability allows you to run them on serverless with minimal effort.

Note: The Rack apps do not have reside in the app/racks folder. They only need to be in a folder that is autoloaded.

Mount Hash Notation

You can also use the hash notation to mount apps.

config/routes.rb

Jets.application.routes.draw do
  mount RackApp => 'rack'
  # mount RackApp, at: 'rack' # same thing
end

Examples

For an example project demonstrating the use of mount, check out rubyonjets/jets-routes-mount.

Gemfile Dependencies

When you mount a Rack app, you must also remember to add the its dependencies to your Gemfile. For example, if you are mounting a Sinatra app, then add the sinatra gem to Gemfile:

gem "sintara"

Mount at Root

To mount at the homepage root use an empty string for the at option. Example:

Jets.application.routes.draw do
  mount GrapeApp, at: '' # app/racks/grape_app
end

Custom Domain

When you deploy your application, API Gateway will add the stage name to the path. Here’s an example with the dev stage: https://xbrp9dekhc.execute-api.us-west-2.amazonaws.com/dev

For Jets apps, the url helpers will add the stage name as necessary. Other frameworks do not have url helpers that account for API Gateway stage names. Applications usually referred to links by their document root url. For example, <a href=/posts>Posts</a>. So you’ll end up with this:

https://xbrp9dekhc.execute-api.us-west-2.amazonaws.com/posts # doesnt work

Instead of:

https://xbrp9dekhc.execute-api.us-west-2.amazonaws.com/dev/posts # works

A quick way to fix this is use a Custom Domain. Custom domain urls not have a stage name appended and will look something like this:

https://demo-dev.example.com/posts # works

General Recommendation

For lightweight frameworks like Sinatra and Grape mounting them is recommended. For heavier frameworks like Rails, mounting will not work due to name collisions.