Mount Rack Apps
Jets Routing supports mounting Rack applications. Example:
mount GrapeApp, at: 'grape' # app/racks/grape_app
mount SinatraApp, at: 'sinatra' # app/racks/sinatra_app
mount RackApp, at: 'rack' # app/racks/rack_app
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.
mount RackApp => 'rack'
# mount RackApp, at: 'rack' # same thing
For an example project demonstrating the use of mount, check out rubyonjets/jets-routes-mount.
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
Mount at Root
To mount at the homepage root use an empty string for the
at option. Example:
mount GrapeApp, at: '' # app/racks/grape_app
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
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
For lightweight frameworks like Sinatra and Grape mounting them is recommended. For heavier frameworks like Rails, mounting will not work due to name collisions.