Homebrew switch & pin

Yesterday I updated and upgraded my Homebrew packages

$ brew update && brew upgrade

It seemed to work fine. The next day I restarted my computer and noticed that Postgres hadn’t started. When I tried to start it I got this error message:

$ pg_ctl -D /usr/local/var/postgres start
server starting
FATAL:  database files are incompatible with server
DETAIL:  The data directory was initialized by PostgreSQL version 9.5, which is not compatible with this version 9.6.5.

What happened? Postgres updated to version 9.6.5 but my database was initialized to 9.5. Whoops. To list all installed versions of Postgres I used this command:

$ brew ls --versions postgresql
postgresql 9.5.5 9.6.1 9.6.2 9.6.3 9.6.4 9.6.5

I then switched back to a Postgres version that was already installed (in my case 9.5.5):

$ brew switch postgresql 9.5.5

After doing this I did a little research and discovered brew pin:

$ brew pin postgresql

This stops Postgres from updating when I brew upgrade so I will never have this problem again (with Postgres).

Ember Fastboot

FastBoot allows Ember to be rendered on both a server and browser instead of only a browser. Ember is great after it’s downloaded however on first page load downloading and evaling javascript in the browser takes too long. FastBoot is the best of both worlds, you get a fast initial page load and fast interactions after loading.

ember-fastboot.com has a great tutorial on how to get started, so I’m going to focus on specific issues I ran into when trying to implement FastBoot.

Setting up the development environment

The development environment was the most frustrating part of working with FastBoot in my opinion. Currently, live reloading doesn’t work so any time I wanted to make a change I had to restart the FastBoot server. Also there’s no proxy option for ember fastboot so you need to add an adapter host.

Authentication

Authentication with FastBoot isn’t too hard, really. The main issue I ran into was realizing that FastBoot makes API calls too and consequently it needs auth headers. So, if you’re authenticating with a cookie, you need to pull the cookie off of the request to the FastBoot server and then send that along with future requests. The easiest way I found to do this is with an adapter header.

What to defer

By deafult FastBoot tries to call all of your model hooks and renders the page based on those hooks. So if you have a widget on your page that makes an AJAX call that isn’t in a model hook it’s not going to get called. There’s a function called deferRendering that can get around this which I haven’t used yet but it’s something to be aware of.

The shoebox

When you’re using FastBoot a lot of work is duplicated because the same code is used for both the server and client. For example, when your route makes an API call it happens in both FastBoot and on the client. The solution to this is the shoebox. The shoebox lets fastboot render your model’s JSON on index.html and load that into the store from the client. I recommend taking a look at ember-data-fastboot and adapting to your needs.