in General Coding

Deploying a Meteor app to Galaxy – a step-by-step guide

Meteor recently announced that they will not continue to support free hosting, starting March 25. Luckily, there are several low-cost hosting options out there, including Meteor’s own Galaxy hosting, which has a pay-as-you-go option.

Here is walk-through of how to deploy a Meteor app to Galaxy.  The folks at Galaxy do provide their own instructions for deploying, but I found I had to do a lot of jumping around to figure everything out, and thought I’d instead create a streamlined tutorial.

Update: MDG recently posted a more streamlined guide to deploying to Galaxy.  Check it out.

1. Create a Meteor app

It’s a good idea to create a dummy app just to be used for learning purposes and ensure that you’re able to deploy an app properly to your target environment before trying to deploy your “real” app, so let’s do that.

In your terminal, type
meteor create [app-name]
Go ahead and run your app locally just to make sure everything was set up properly:
cd [app-name]
meteor

You should now be able to view the default Meteor app at http://localhost:3000 in your browser.

We’ll be coming back to the app in a bit, but first we need to create a Galaxy account and a Mongo database.

2. Sign Up for Galaxy

Go to the Galaxy Signup page. Be sure to select the “Basic” option and click continue.

Select the basic option when signing up for galaxy

Select the basic option when signing up for galaxy

Enter your signup info (or sign in with your meteor developer account) and add your payment info.

3. Add a MongoDB Database

This part is a bit confusing. One would expect for the next step to be to head over to your Galaxy Dashboard and create an app. Instead, you need to first create a Mongo database for your app. For this, we’ll use mLab, which is what the folks at Galaxy recommend.

Head over to mLab and create an account:

mlab signup

mlab signup

Once you’ve completed the signup process, you should be able to sign in and see your dashboard.

Click on “Create New” to start creating a database.

Create a Mongo db at mLab

Create a new db

You should now see a screen that looks something like this:

Create db, default view

Create db, default view

Click on the ‘Single-Node’ tab, and you should see the following:

Create a sandbox db

Create a sandbox db

Be sure to select the Sandbox option.  Then, enter a name for your database, eg “myapp_mongodb”.

Next, click on  “Create new MongoDB deployment”.

After a moment, you should see your db in the dashboard.

mlab db dashboard

mlab db dashboard

4. Add a db user

Next, we need to add a user to the database, which will be needed when we want to associate the database with our app.

Click on the db name to view details about the database.

view db details

View db details

This is the dashboard for the specific database you created.

mlab db details

mlab db details

  1. Click on the ‘Users’ tab
  2. Click on ‘Add database user’
  3. Enter a username and a password.  For the username, pick something specific to your app, eg “myAppAdmin” and be sure your password is relatively secure. (Make a note of this info, you’ll need it later.)
  4. Ensure “read-only” is not checked:
Adding a mLab user

Adding a mLab user

As interfusion explains on the Meteor forums:

Maybe it’s just me, but when I saw the mLab read-only setting for username and password, I thought that mLab was asking whether I wanted to deny any incoming web API requests to change the database login credentials, so I set it to true. It turns out that this setting must be for database documents, not the login credentials.

Your should now see something like this:

mlab db with user added

mlab db with user added

5. Create a settings file for galaxy deployment

Next, we need to create a Meteor settings file for when we deploy to galaxy.  This file will contain the following:

  • A link to the database we just created.
  • The URL of our app.

Your settings file can contain a lot more than this, but this is the minimum you’ll need.

Head back your app directory and create a settings.json file:

You can call this file anything you want, though it does need to end in “.json” I recommend placing your settings files in a “private” directory (which is a special directory in the Meteor context) but here we’ll just leave it in the root directory, to keep things simple.

Add the following to your settings file:

Your app URL – using *.meteorapp.com if you don’t have a custom domain name

If you want to deploy your app and you don’t have a custom domain name, you might have expected that you would deploy to *.meteor.com as before, but that won’t work.  You need to use the new *.meteorapp.com sub-domain instead.

Your app URL – using a custom domain name

If you had a custom domain name, you would insert that in the same spot, and you would need to point your DNS (in your registrar’s dashboard) to galaxy-ingress.meteor.com. Learn more. (Thanks to jaclynn for prompting me to add this info.)

Deploying directly to *.meteorapp.com is the perfect choice for a quick test app.   With that in mind, enter the app URL as follows: “http://my-cool-app.meteorapp.com”  (Tip:  Try navigating to the *.meteorapp.com domain first to make sure it is not already in use.)

Your MongoDB URI

This part is a little tricker.  First, go to the dashboard for the database you created. (See above.) Then, copy the URI that was created for this db:

mlab db uri

mlab db uri

Paste the URI into the settings file in the “[YOUR MONGODB URI]” location.  Replace the <dbuser> portion with the username of the user you added to this database.  Replace the password portion with the password you created.

Your settings file should now look something like this:

What about MONGO_OPLOG_URL?

You might have noticed in the galaxy help instructions that there is mention of a “MONGO_OPLOG_URL”  This is used by Meteor to “tail” output from MongoDB to get real-time data updates.  However, while using this option improves performance, and is recommended for a production app, it is not a requirement for deploying an app to Galaxy.  Also, the option doesn’t exist for a mLab Sandbox app :-}
(Thanks to timfletcher for prompting me to add this.)

Ok, we’re now finally ready to deploy your app!

6. Deploy the app to galaxy

Make sure you are in the root directory of your app.  In your terminal, add the following:

You might be asked to enter email and password here. Be sure to enter your info for your Meteor developer account.

If all went well, you should be able to sign in your galaxy dashboard and see a green dot next to your app. And, of course, you can also navigate to http://my-meteor-app.meteorapp.com to view your app live.

 

Windows user?

Note that if you are a windows user, you’ll need to divide this into two steps:

Thanks to rohit2b for pointing this out.

Troubleshooting

It’s common that something goes wrong the first time you deploy your app.  These are some of the more common issues:

  • You got your login info wrong for your database.
  • There was a typo in your deploy command. This command is pretty long, so it’s easy to make a mistake.
  • Your settings file was improperly formatted (maybe you forgot a comma somewhere?)

If all else fails, view your logs…

If something isn’t working and none of the above apply, try checking the logs.  Go to your Galaxy dashboard and click on “Logs” to see what might have gone wrong.

You can also view your logs by navigating to:

(Thanks to interfusion for this tip.)

7. Bonus Step: Create a short deploy command

That deploy command is pretty long and you are likely to use it a lot.  So, it’s a good idea to create a shorter version of the command.  This will not only save time but help prevent annoying typos.

Here, we’ll use npm but there are many other ways you can do this, such as create a shell script or use a tool like Gulp.

First, you’ll need to make sure you have Node installed.  To make sure,  type this in your terminal:

You should see a version number.

Next, let’s initialize npm for your app.  In your app directory, type:

This will create a package.json file in your app directory.

Open up this file and paste the same command you typed above inside the “scripts” block as follows:

Save the file and then return to your terminal command line.  If everything was done correctly, you should now be able to type the following whenever you want to deploy your app:

That’s it!  Hopefully, this will help some people avoid some of the roadblocks I encountered when figuring out how to deploy on Galaxy.

If I got anything wrong in the above instructions, please do let me know in the comments.

Add a Comment

Comment

19 Comments

  1. If you are getting: “503 Service Unavailable: No healthy endpoints to handle the request” check your error logs. If the error logs are saying that “ROOT_URL” is bad, then try putting http:// before the URL. That worked for me! Also put that same URL on the deployment line.

  2. After following this tutorial I am getting this error, can you help me, please?

    503 Service Unavailable: No healthy endpoints to handle the request.

  3. Naïm and Carlos – thanks for raising this issue. I can’t say for sure what the specific issue is, but I’d suggest the following:

    – Check your settings file. Is there possibly a typo in your ROOT_URL?
    – Go into your Galaxy console. Is Galaxy detecting your app? Are there any helpful log messages?
    – Check out the official guide for deploying to Galaxy which, at this point, is likely to be more up-to-date than this blog post: http://galaxy-guide.meteor.com/deploy-guide.html

    Hope that helps.

  4. Hello,

    I’m facing the same issue that Carlos reported with a custom subdomain on meteorapp.com . I’m pretty sure I followed your tutorial correctly. The only particular thing I can think of in my case is that I’m deploying to European AWS

    By the way, thanks for the article!

  5. Hi all:

    I think I follow the tutorial step by step, but my browser show me the message:

    404 Not Found: No applications registered for host ‘edugroups.meteorapp.com’.

    Why? :(

  6. Hi all:

    I think I follow the tutorial step by step, but my browser show me the message:

    404 Not Found: No applications registered for host ‘edugroups.meteorapp.com’.

    Why? :-(

  7. Excellent breakdown, wit your help I was able to read my logs and find Meteor was reporting mongo auth failed. With more digging on othe boards, I found out that the version of meteor that I was using did not work with mLab/galaxy.

    1.0.3 of Meteor DOES NOT work on mLab/Galaxy installations
    1.0.4 WORKS after local upgrade and deployment

  8. You’re amazing. This helped me so much.

    Things I got stuck on that are probably my dumb mistakes but might help some poor soul:

    1. For my Mongo URI I put ‘http://’ in front of it even though I shouldn’t have.
    2. No, a ‘Mongo Oplog URL’ isn’t necessary. I believe it’s a sort of backup database, but you can deploy without it.
    3. A root URL is not needed unless, I think, you are hosting it to your own custom URL. This is something I’m having trouble with. If anyone could help me I’d really appreciate it.

  9. Hey! Great stuff.. just working through this now for the first time. So I’m being asked for email and password after the deploy command… Not mentioned in your guide… I don’t think? Maybe worth adding. Thanks

Webmentions

  • Meteor DevShop: Deploy a Meteor App to Galaxy – Coder Chronicles March 16, 2016

    Very helpful, thanks so much!