Front-End Builds (FEB) lets you easily serve remotely-hosted static (JS) applications from your Rails apps. For example, you can host a Rails backend on Heroku, an Ember.js frontend on S3, and use FEB to connect the two.
- JS app can be deployed without redeploying your Rails app
- Easily smoke test SHAs, branches and releases in your production environment with query params: http://your-app.com/my-ember-app?branch=new-feature
- Admin interface lets you easily view, rollback and activate different app versions
The motivation for this gem came from Luke Melia's RailsConf2014 talk.
Add this line to your application's Gemfile:
And then execute:
Front-End Builds brings some migrations along with it. To run, execute
rake front_end_builds:install:migrations rake db:migrate
First, mount the admin interface in
Rails.application.routes.draw do mount FrontEndBuilds::Engine, at: '/frontends' end
You should mount this under an authenticated route using your application's auth strategy, as anyone with access to the admin will be able to affect the production builds of your front end apps.a
If you don't want to set up an HTML auth strategy, you can do something like this:
# routes.rb protected_app = Rack::Auth::Basic.new(FrontEndBuilds::Engine) do |username, password| username == 'admin' && password == (Rails.env.production? ? ENV['FEB_ADMIN_PASSWORD'] : '') end mount protected_app, at: '/frontends'
This will use basic HTTP auth to secure access to your admin ui. Just set the ENV variable in production, and use it to gain access. If you're deploying to Heroku, use Config Vars.
Now, to create a new app, first add a
front_end route pointing to your app in
Rails.application.routes.draw do front_end 'app-name', '/app-route' end
Visit the admin (at whatever URL you mounted the engine above), create a
new app named
app-name, and you'll receive instructions on how to
start pushing builds.
If you're using this engine to serve an ember app at the Root, be sure to put all other Rails routes above the
front_end route - as this takes priority over all routes below it!
Rails.application.routes.draw do # All other Rails routes here front_end 'app-name', '/' end
At this point you should be able to test the setup in dev by running
/frontends to access the Admin interface, and visit the
front_end route, which will initially return 404 Not found since you haven't configured and deployed any front-end builds yet.
Example Next Steps with Heroku and Ember.js
A common configuration is to deploy your FEB-enabled Rails app to Heroku, and deploy your Ember.js frontend to S3:
- Deploy your Rails app to Heroku
- Configure your frontend app with ember-cli-deploy-front-end-builds-pack
- Access your Rails app's FEB Admin interface, add an app, and configure a public SSH key that corresponds to the private key you plan on using to sign your Ember.js builds
- Deploy your frontend app. If all goes well, it should build the Ember app, push the static assets to S3, then POST to your Rails app. You'll see the build in the Admin interface, and should be able to access your frontend at the
front_endroute you specified.
The Admin interface is an Ember CLI app within feb. A distribution is kept within the gem, and must be updated whenever admin code is updated.
After changing the admin app, run
to store a fresh distribution.
# Rails tests rspec # Admin tests, from /admin dir ember test
- Create docs site
- Auto live setting
- make posts idempotent (i think they are), but dont insert a new row if it already exists.