Fastboot is a way to run your Ember application in Node. It allows your site to be used even when JavaScript isn't available, and allows your site to be search engine friendly. It works by delivering to the user server rendered code, then "rehydrating" that code with JavaScript when your assets finish loading. Perhaps the best thing about the way Ember implements Fastboot is how easy it is to add to your Ember application. Because Ember embraces the idea of strong conventions, Fastboot can make some assumptions about how to build your app in node-land and can deliver solid, functioning server-rendered content, which is then converted in the browser to a dynamic client side app. Fastboot is a way to try and have it all.
Let's look at adding fastboot to our School Directory app that we deployed
yesterday. Maybe the easiest way to get this running locally is to run our Rails
api app from yesterday locally on port 3001 (we need port 3000 for our fastboot
server), making sure our host in
app/adapters/application.js
is
localhost:3001
, and making sure our Rails API has
localhost:4200
and
localhost:3000
as it's permissible origins in
RAILS_ROOT/config/initializers/cors.rb.
Rails.application.config.middleware.insert_before 0, Rack::Cors do
allow do
# origins 'dailydrip-school-directory.herokuapp.com'
origins 'localhost:4200', 'localhost:3000'
resource '*',
headers: :any,
methods: [:get, :post, :put, :patch, :delete, :options, :head]
end
end
Start your rails server, from your Rails root:
rails s -p 3001
To install Ember Fastboot, from the root of your Ember app, type:
ember install ember-cli-fastboot
Then, to start your fastboot server in development just type
ember fastboot
--serve-assets
. Now, if you open your site at http://localhost:3000, you will
be seeing a server rendered version of your site.
You can use curl to see your server generated Ember app:
curl
localhost:3000/contacts
and
curl localhost:3000/contacts/1
both produce the
results we would expect from a server generated site.
Finally, the only thing you have to do to deploy your site is change your host
in
app/adapters/application.js
back to your production Rails API. Then commit
and deploy to heroku:
git add .
git commit -m'added fastboot'
git push heroku 11.2.start:master
That's it, now you should have Fastboot running in production. To see other strategies for deploying your fastboot application you can see the link about deploying Fastboot below.
Comments for Fastboot