Congratulations! You've reached the final stage of developing your Ember app: it's time to deploy it to a server so that everyone can start using it!
There are many ways that you can deploy your application. In this chapter we're going to use Heroku.
Set up Heroku
The first thing you need to do, if you haven't yet, is create a Heroku account (don't worry, it's free)!
Next, you need to install the Heroku Toolbelt on your computer. Just follow the instructions on the page and log in with your credentials in their command line tool.
Now, make sure that you're in the Chirper Ember folder and run this command to create your Heroku app using the Ember Heroku Buildpack (the namespace my-chirper-app needs to be unique, so you're going to have to come up with your own name):
You can deploy to Heroku using simple Git commands, which is awesome. If you haven't commited anything in your project yet, we'll do it now:
And finally, we push the application to the Heroku server:
This might take a few minutes, so just sit tight and let the buildpack do it's thing. The first deploy is always a little extra long since Heroku will cache the node_modules directory in order to speed up future builds.
When it's done, visit http://{your-app-namespace}.herokuapp.com
(in my case, it will be my-chirper-app.herokuapp.com) and you should see your web app, live!
Deploying the API
There's an important piece still missing, namely the API! If you try to log in or sign up, you'll notice that nothing happens, so let's deploy our November app as well!
We'll start by going back to our November directory in the terminal, and create a Heroku app for it (remember, choose a unique namespace):
Next, we commit and deploy a first version of the app:
When it's done, you can check out your app in the browser by running heroku open.
Right now, our live API isn't linked to any production database though.
Heroku uses PostgreSQL as their default database, which Sequelize (and therefore November) supports out of the box. This allows us to use a PostgreSQL database in production while still using MySQL when we develop locally. Sweet!
Let's add a database to our app by going back to the Heroku Dashboard:
Before we redeploy, we need to specify the allow_origin
in November's config-file (under the production
key), so that our Ember app can make AJAX requests to our API in production:
Alright, let's redeploy this!
After it's done, visit https://{your-api-namespace}.herokuapp.com/users
and if you see an empty array, that means that the database tables were created successfully!
Fixing the Ember app
Finally, we need to set some environment variables for the API URL in our Ember app as well, so that it connects to the Heroku URL instead of localhost:9000 when we ship it.
Commit and redeploy your Ember app:
That's it! Now your app is deployed with a working API and you can take some time off to CELEBRATE!
Comments
You need a Ludu account in order to ask the instructor a question or post a comment.
Help! I'm getting <p class="p1">
$ git add .
</p> <p class="p1">fatal: Not a git repository (or any of the parent directories): .git
even though I ran the heroku create </p>
I also recommend the following if you see a fatal error about "'heroku' does not appear to be a git repository. Could not read from remote repository." - http://stackoverflow.com/questions/18406721/heroku-does-not-appear-to-be-a-git-repository
Judging from http://stackoverflow.com/questions/3755529/git-remote-doesnt-seem-to-be-working-at-all I think you need a "git init" in there -- perhaps thats covered by the buildpack in the ember heroku push ?
Also I needed this info: http://stackoverflow.com/questions/17626944/heroku-permission-denied-publickey-fatal-could-not-read-from-remote-reposito
it's asking for "your development language"... I'm assuming node.js ...
<p class="p1">I get a "Pruning cached bower dependencies not specified in bower.json</p><p class="p1"> </p><p class="p1">remote: /tmp/buildpack_4c55cd9f699a46737891123cabec629c/bin/compile: line 186: bower: command not found"</p>
Fix seems to be "heroku config:set REBUILD_ALL=true" at https://github.com/tonycoco/heroku-buildpack-ember-cli/issues/103 - man there's a lot that go wrong :-(
it's now called "Provision" not "save"
It could be worth pointing out this is one line of command... also, reassuring people that "we'll use tonycoco's buildpack" so the novice doesn't try and replace anything in the url for that
I got an error because of the / at the end of the allow_origin url. Removing the slash made it work as expected.
Why did you decide to use MySQL for development, rather than PostgreSQL for both?
@alidlorenzocastano: No particular reason actually. Usually I find MySQL has more tools available to the developer (apps like Sequel Pro for Mac are great for example)! And since November is database-agnostic, I thought "why not". I prefer Postgres though. :)