Mount Rack Apps
Jets Routing supports mounting Rack applications. Example:
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
Note: The Rack apps do not have reside in the
app/racks folder. They only need to be in a folder that is autoloaded.
For an example project demonstrating the use of mount, check out tongueroo/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:
Jets.application.routes.draw do mount GrapeApp, at: '' # app/racks/grape_app end
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 is not currently recommended. See: Mounting Rails Apps.
Pro tip: Use the <- and -> arrow keys to move back and forward.